作者:yishengyishi2004929_621_834 | 来源:互联网 | 2023-10-12 12:28
话不多说上代码!user_list[{user:zhangsan,password:111111,balance:1000},{user:lisi,password:222222,
话不多说上代码!
user_list = [{'user': 'zhangsan', 'password': '111111', 'balance': 1000},
{'user': 'lisi', 'password': '222222', 'balance': 2000},
{'user': 'wangwu', 'password': '333333', 'balance': 3000}]
current_user = None
def reg():
print('这是一个注册功能!')
while True:
un = input('请输入您的用户名:')
for item in user_list:
if un.strip() == item['user']:
print('您输入的用户名已存在,请重新输入')
break
else:
pw = input('请输入您的密码:')
if len(pw) <6:
print('密码不能小于6位!')
else:
user_list.append({'user': un, 'password': pw, 'balance': 3000})
print('注册成功!')
return True
def login():
print('这是一个登录功能!')
while True:
un = input('请输入您的用户名:')
pw = input('请输入您的密码:')
for user in user_list:
if user['user'] == un and user['password'] == pw:
print('恭喜你登录成功!')
global current_user
current_user = user
print('当前登录用户为:', current_user['user'])
return
else:
print('用户名或密码错误!')
def check_current():
if current_user:
print('当前余额为:',current_user['balance'])
else:
print('请先登录再进行查询操作!')
def deposit():
if current_user:
mOney= input('请输入您要存款的金额:')
if money[-2:] == '00' and len(money) > 2 and int(money) > 0:
current_user['balance'] += int(money)
print('存款成功!')
else:
print('您输入的金额有误!')
else:
print('请先登录再进行存款操作!')
def withdrawal():
if current_user:
mOney= input('请输入你要取款的金额:')
if money[-2:] == '00' and len(money) > 2 and int(money) > 0:
if int(money) > current_user['balance']:
print('余额不足!')
else:
current_user['balance'] -= int(money)
print('取款成功!')
else:
print('您输入的金额有误!')
else:
print('请先登录再进行存款操作!')
def transfer():
if current_user:
to_user = input('请输入需要转账的账户名:')
if to_user == current_user['user']:
print('不能给自己转账!')
else:
for user in user_list:
if to_user == user['user']:
mOney= input('请输入需要转账的金额:')
if money[-2:] == '00' and len(money) > 2 and int(money) > 0:
if int(money) > current_user['balance']:
print('余额不足!')
else:
current_user['balance'] -= int(money)
user['balance'] += int(money)
print('转账成功!')
else:
print('您输入的金额有误!')
break
else:
print('您输入的账户不存在!')
else:
print('请先登录再进行转账操作!')
def get_menu():
menu = '''
***请选择您要操作的菜单***
**1.注册 2.登录 3.查询余额 4.存款 5.取款 6.转账 7.退卡**
'''
while True:
print(menu)
op = input('请输入您的选择:')
if op == '1':
reg()
elif op == '2':
login()
elif op == '3':
check_current()
elif op == '4':
deposit()
elif op == '5':
withdrawal()
elif op == '6':
transfer()
elif op == '7':
print('您已成功退出!请取走您的卡片。')
break
else:
print('无此选项!')
get_menu()