首页 > 其他 > 详细

ATM

时间:2020-08-01 12:28:58      阅读:116      评论:0      收藏:0      [点我收藏+]

  

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}\n)
    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}\n)
    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}\n)
        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("非法操作")

 

ATM

原文:https://www.cnblogs.com/yjc53/p/13413929.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!