欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

python基础之模拟ATM注册、登录、查询余额、存款、取款、转账、退卡(原代码)

时间:2023-08-27

curruent_users = Noneusers = [{'username': 'lili', 'password': '123456', 'banlance': 30000}, {'username': 'tt',' password': '123478', 'banlance': 23000}]def getmuen(): muen=''' ****欢迎来到WonluiuATM**** *******操作菜单******* ****1、注册 2、登录 3、查询余额 4、存款 5、取款 6、转账 7、退卡**** ''' while True: print(muen) opt = input('请输入你想要选择的菜单:') if opt == '1': reg() elif opt == '2': login() elif opt == '3': search() elif opt == '4': deposit() elif opt == '5': withdrawal() elif opt == '6': tansform() elif opt == '7': print('欢迎下次光临') break else: print('请输入正确的数字')def reg(): while True: p = input('请输入用户名:') m = input("请输入密码:") for item in users: if p == item['username']: print('用户已存在!!') break else: if len(m) < 6: print('密码小于6位数') break else: users.append({'username': p, 'password': m, 'banlance': 3000}) print('用户注册成功,请重新登录!!') return Truedef login(): while True: h = input('请输入用户名:') m = input("请输入密码:") for it in users: if it['username'] == h and it['password'] == m: print('用户登录成功') global curruent_users curruent_users = it return else: print('用户名或者密码错误!')def search(): if curruent_users: #代表登录成功了 print('当前用户得余额为:', curruent_users['banlance']) else: print('请先登录在查询')def deposit(): if curruent_users: h = int(input('请输入存入的数目:')) if h % 100 == 0: curruent_users['banlance'] += h print("目前的金额为 ", curruent_users['banlance']) else: print('请正确的金额') else: print('请先登录在查询')def withdrawal(): if curruent_users: h = int(input('请输入取的数目:')) if h[-2:] == '00' and len(h) > 2: if curruent_users['banlance'] >= h: curruent_users['banlance'] -= h else: print('余额不足') else: print('请存取100的整数') else: print('请先登录在查询')def tansform(): if curruent_users: h = input('请输入转账的账户名称') if curruent_users['username'] == h: print("不能给自己转账") else: for item in users: if item['username'] == h: f = input("请输入转账的金额") if h[-2:] == '00' and len(h) > 2: if curruent_users['banlance'] >= int(h): curruent_users['banlance'] -= int(h) curruent_users['banlance'] -= int(f) item['banlance'] += int(f) else: print('余额不足') else: print('输入的金额有误') break else: print('请输入正确的账户') else: print('请先登录在查询')getmuen()

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。