代码:转账,取款,存款,查询余额,更改密码

flag = True
d = {}
with open('b.txt', mode='rt', encoding='utf-8') as f:
res = f.readlines()
for line in res:
i = line.strip('\n').split(':')
d[i[0]] = i[1]
# print(d) # {'egon': '123', 'yanglong': '789'}
while flag:
inp_user = input('请输入您的账号>>>:').strip()
# print(d) # {'egon': '123', 'yanglong': '789'}
# 这个主要是想证明 inp_user = 'egon'没有关系
if inp_user not in d:
print('对不起用户名不存在,请重新输入')
continue
else:
inp_pwd = input('请输入您的密码>>>:').strip()
# print(d) # {'egon': '123', 'yanglong': '789'}
if d[inp_user] == inp_pwd:
print('登录正确')
while flag:
print('查询余额请按1')
print('转账请按2!')
print('存款请按3!')
print('取款请按4!')
print('更改密码请按5')
print('退出请按0')
commend = input('请选择您的操作>>>:')
if commend == '1':
while flag:
# item = inp_user
d = {}
with open('a.txt', mode='rt', encoding='utf-8') as f:
res = f.readlines()
for line in res:
i = (line.strip('\n')).split(':')
d[i[0]] = i[1]
print('您的余额还有', d[inp_user])
print('返回主菜单请按1,退出请按2')
commend = input('请选择您的操作>>>:')
if commend == '1':
continue
elif commend == '2':
flag = False
elif commend == '2':
while flag:

username = input('请输入转账用户名>>>:')
# 用户名是否存在
if username in d:
while flag:
d = {}
with open('a.txt', mode='rt', encoding='utf-8') as f:
res = f.readlines()
for line in res:
i = line.strip('\n').split(':')
d[i[0]] = i[1]
money = input('请输入转账金额>>>:')
if int(d[inp_user]) > int(money):
res1 = int(d[inp_user]) - int(money)
res2 = int(d[username]) + int(money)
with open('a.txt', mode='at', encoding='utf-8') as f:
line1 = '%s:%s\n' % (inp_user, res1)
line2 = '%s:%s\n' % (username, res2)
f.write(line1)
f.write(line2)
print('转账成功,您当前余额为', res1)
print('继续转账请按1,返回主菜单请按2,退出请按3')
commend = input('请选择您的操作>>>:')
if commend == '1':
continue
# elif commend == '2':

elif commend == '3':
print('再见')
flag = False
else:
print('转账失败,余额不足,请重新输入')
continue
else:
print('用户名不存在,请重新输入')
continue

elif commend == '3':
d = {}
while flag:
with open('a.txt', mode='rt', encoding='utf-8') as f:
res = f.readlines()
for line in res:
i = line.strip('\n').split(':')
d[i[0]] = i[1]
money = input('请输入存款金额>>>:')
res1 = int(money) + int(d[inp_user])
with open('a.txt', mode='at', encoding='utf-8') as f:
res2 = '%s:%s\n' % (inp_user, res1)
f.write(res2)
print('存款成功,当前余额为', res1)
print('继续存款请按1,退出请按2')
commend = input('请输入您的选择>>>:')
if commend == '1':
continue
else:
print('再见')
flag = False

elif commend == '4':
d = {}
while flag:
with open('a.txt', mode='rt', encoding='utf-8') as f:
res = f.readlines()
for line in res:
i = line.strip('\n').split(':')
d[i[0]] = i[1]
money = input('请输入取款金额>>>:')
if int(d[inp_user]) > int(money):
res = int(d[inp_user]) + int(money)
with open('a.txt', mode='at', encoding='utf-8') as f:
res1 = '%s:%s\n' % (inp_user, res)
f.write(res1)
print('取款成功,请等待查收')
print('继续取款请按1,退出请按2')
commend = input('继续or退出>>>:')
if commend == '1':
continue
else:
print('再见')
flag = False
else:
print('取款失败,余额不足')
continue

elif commend == '5':
while flag:
password = input('请输入您的旧密码>>>:').strip()
if d[inp_user] == password:
while flag:
password1 = input('请输入您的新密码>>>:').strip()
password2 = input('请再次输入您的新密码>>>:').strip()

if password1 == password2:
with open('b.txt', mode='at', encoding='utf-8') as f:
res = '%s:%s\n' % (inp_user, password2)
f.write('res')
print('密码更改成功,请重新登录')
flag = False
else:
print('俩次密码输入不相同,请重新输入')
continue

else:
print('密码不正确,请重新输入')
continue

elif commend == '0':
flag = False

else:
print('密码错误,请重新输入')
continue
posted @ 2021-06-14 20:19  点滴180  阅读(6)  评论(0编辑  收藏  举报