zoukankan      html  css  js  c++  java
  • ATM

      

    import  os
    def login(*args):
        """登录"""
        in_username = input("请输入您的账号:")
        in_paaswd = input("请输入您的密码:")
        with open('user.txt',mode='rt',encoding='utf-8') as f:
            for line in f:
                username1,paswd = line.strip().split(',')
                if in_username == username1 and in_paaswd == paswd:
                    print('登录成功')
                    break
    
            else:
                print('登录失败')
    
    def registered():
        """注册"""
        newuser=input("请输入您的用户名:")
        newpaswd=input("请输入您的密码:")
        moeny = input("请输入您的余额")
        with open('user.txt',mode='rt',encoding='utf-8') as f,
            open('user.txt',mode='at',encoding='utf-8') as f1,
            open('db.txt',mode='at',encoding='utf-8') as f2:
                for line in f:
                    user,paswd = line.strip().split(',')
                    if user != newuser:
                        f1.write('{}:{}'.format(newuser,newpaswd))
                        f2.write('{}:{}'.format(newuser,moeny))
                        print("注册成功")
                    elif newuser == user:
                        print("用户已经存在")
                        break
    
    
    
    
    def withdraw():
        """"提现"""
        user=input("请输入账号:")
        hq=int(input("请输入要提取的额度:"))
        dic = {} #定义空字典
        with open('db.txt',mode='rt',encoding='uft-8') as f,
            open('.db.txt.sawp',mode='wt',encoding='utf-8') as f1:
            for line in f:
                username,moneny= line.strip().split(',')
                dic[username]=int(moneny)
            print("还剩余额度为",dic[user])
            if dic.get(moneny) > hq:
                print("余额不足")
            else:
                dic[user] -= (hq * 0.5)
                print('还剩余',dic[user])
                for username,moneny in dic.items():
                    f1.write(f'{username}:{moneny}
    ')
        os.remove('db.txt')
        os.rename('.db.txt.swap','db.txt')
    
    def hub():
        """转账"""
        source=input("请输入账号:")
        end = input("请输入目标账号:")
        moeny= int(input("请输入转账金额"))
        dic={}
        with open('db.txt',mode='rt',encoding='utf-8') as f,
            open('.db.txt',mode='wt',encoding='utf-8') as f1:
            for line in f:
                username,moeny1 =line.strip().split(',')
                dic[username] = int(moeny1)
                print('您的账户余额为',dic[source])
            if dic.get(source) > moeny:
                dic[source] -= moeny # 原用户扣钱
                dic[end] += moeny # 目标用户加钱
                print("成功转账,您的账户余额",dic[source])
            elif dic.get(source) < moeny:
                print("余额不足")
            for username,moeny1 in dic.items():
                f1.write(f'{username},{moeny1}
    ')
        os.remove('db.txt')
        os.rename('.db.txt','db.txt')
    
    def also():
        """还款"""
        in_user=input("请输入您的账号")
        in_moeny=int(input("请输入还款金额"))
        dic={}
        with open('db.txt',mode='rt',encoding='utf-8') as f,
            open('.db.txt',mode='wt',encoding='utf-8') as f1:
            for line in f:
                username,moeny = line.strip().split(',')
                dic[username]=int(moeny)
            print("您的账户余额",dic[in_user])
            dic[in_user] += in_moeny
            for username,moeny in dic.items():
                f1.write('{username}:{moeny}
    ')
            os.remove('db.txt')
            os.rename('.db.txt','db.txt')
    select='1 登陆 ,2 注册,3 转账 ,4 还款 '
    print(select)
    
    
    operating=input("请选择你的操作")
    if operating == '1':
        login()
    elif operating == '2':
        registered()
    elif operating == '3':
        hub()
    elif operating == '4':
        also()
    else:
        print("非法操作")
  • 相关阅读:
    Linux的sz和rz命令
    python正则表达式(8)--分组、后向引用、前(后)向断言
    python正则表达式(7)--flag修饰符、match对象属性
    python正则表达式(6)--split、sub、escape方法
    python正则表达式(5)--findall、finditer方法
    python正则表达式(4)--search方法
    python正则表达式(3)--match方法
    python正则表达式(2)--编译正则表达式re.compile
    Go语言开发教程
    zabbix源码编译安装以及添加第一台host监控
  • 原文地址:https://www.cnblogs.com/yjc53/p/13413929.html
Copyright © 2011-2022 走看看