curruent_users = None
users = [{'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 True
def 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()
|