学习是一个逐步发现自己无知的过程!

Python练习题之ATM

def login():
    """登陆"""
    count = 0
    tag = True
    while tag:
        if count == 3:
            print("尝试次数过多,退出。")
            break
        inp_name = input("请输入用户名:").strip()
        inp_pwd = input("请输入密码:").strip()
        with open('user.txt', 'r+', encoding='utf-8') as uspwd:
            for i in uspwd:
                user = i.strip().split("|")
                uname = user[0]
                pwd = user[1]
                ed = user[2]
                if inp_name == 'q':
                    break
                if inp_name == uname and inp_pwd == pwd:
                    print(f"登陆成功你的额度为: {ed}")
                    tag = False
                    break
            else:
                print("登陆失败")
                count += 1


def tx():
    """提现"""
    tag = True
    while tag:
        user = input("输入账号:").strip()
        qk = input("提现金额:").split()
        if user == 'q' or qk == 'q':
            break
        with open('user.txt', 'r+', encoding='utf-8') as tx0, \
                open('.user.txt', 'wt', encoding='utf-8') as tx1:
            for i in tx0:
                us = i.strip().split("|")
                uname = us[0]
                ye = us[2]
                if user == uname:
                    print("开始提现")
                    tag = False
                    break
            else:
                print(f"用户不存在")


def zz():
    """转账"""
    age = True
    while age:
        df_zh = input("请输入对方账户:").strip()
        bd_zh = input("请输入转账账户:").strip()
        if df_zh == 'q' or bd_zh == 'q':
            break
        with open('user.txt', 'r+', encoding='utf-8') as zz0, \
                open('.user.txt', 'wt', encoding='utf-8') as zz1:
            for i in zz0:
                user = i.strip().split("|")
                uname = user[0]
                if df_zh == uname:
                    print(f"{df_zh}:账户存在")
                elif bd_zh == uname:
                    zz_je = input("请输入转账金额:").strip()
                    print(f"本次转账金额{zz_je}")
                    age = False
                    break
            else:
                print(f"{bd_zh}:用户不存在重新输入")
                continue


def hk():
    """还款"""
    tag = True
    while tag:
        use = input("请输入你的账户:").strip()
        hkj = input("还款金额:").strip()
        if use == 'q' or hkj == 'q':
            break
        with open('user.txt', 'r+', encoding='utf-8') as hk0, \
                open('.user.txt', 'wt', encoding='utf-8') as hk1:
            for i in hk0:
                user = i.strip().split("|")
                uname = user[0]
                ed = user[2]
                if use == uname:
                    print(f"还需还款{ed}")
                    tag = False
                    break


def start():
    caoz = ['login.登陆', '0.提现', '1.转账', '2.还款', 'q.退出']
    while True:
        inp_caoz = input(f"选择操作{caoz}\n\t: ").strip()
        if inp_caoz == '0':
            tx()
        elif inp_caoz == 'login':
            login()
        elif inp_caoz == '1':
            zz()
        elif inp_caoz == '2':
            hk()
        elif inp_caoz == 'q':
            break
        else:
            print("输入有误重新输入")


start()

 

赞(0)
未经允许不得转载:劉大帥 » Python练习题之ATM

你的评论可能会一针见血! 抢沙发

登录

找回密码

注册