示例:
'''
By challen
自动存取款机管理系统
登陆login user
1.查询余额
2.存款操作
4.取款操作
5.退出用户
'''
bank_database= [
{'id':'1001','user_password':'200101','name': 'zhanggoudan', 'bank_balance': 1002, 'user_grade': 'VIP用户'},
{'id':'1002','user_password':'200202','name': 'liyu', 'bank_balance': 3058, 'user_grade': '白金用户'},
{'id':'1003','user_password':'200303','name': 'goerzi', 'bank_balance': 2994, 'user_grade': '黄金用户'}
]
def login_user_check():
'''
验证登录密码匹配的函数
'''
global bank_database
user_id=input('请输入您的卡片账号')
user_password=input('请输入您的6位密码:')
for NewUser in range (len (bank_database)):
if user_id== bank_database[NewUser]['id'] and user_password == bank_database[NewUser]['user_password']:
print('尊贵的{} {},您已登录成功!请进行下列操作'.format(bank_database[NewUser]['user_grade'],bank_database[NewUser]['name']))
print ('——' * 33)
return NewUser
else:
print('输入的账号密码有误,请重新输入')
break
def check_balance():
"""
查询余额功能
"""
global bank_database
print('您的账户余额还有{}元'.format(bank_database[NewUser]['bank_balance']))
def add_balance():
'''
存款功能
'''
global bank_database
add_money=int(input('请输入存款金额:'))
bank_database[NewUser]['bank_balance']+=add_money
print('尊贵的用户,您的专属账户已成功存入{},目前余额为{}'.format(add_money,bank_database[NewUser]['bank_balance']))
def draw_balance():
"""
取款功能
"""
global bank_database
draw_money= int (input ('请输入取款金额:'))
if bank_database[NewUser]['bank_balance']>=draw_money:
bank_database[NewUser]['bank_balance']-=draw_money
print ('您已成功取款{},目前余额剩余{}'.format (draw_money, bank_database[NewUser]['bank_balance']))
if bank_database[NewUser]['bank_balance'] < draw_money:
print('您的余额不足!')
def loginOut():
user_choose=input('请问是否登出,是请按1,否请按2,请输入:')
while user_choose=='1':
print('已成功登出,请取回你的卡片')
break
else:
print('请继续操作系统')
def welcome_user():
print ("===================================================================")
print (" 欢迎登陆深圳中通银行 ")
print ("===================================================================")
def user_interface():
'''
用户界面的函数
'''
print ("{0:1}{1:<30}{2:>30}{0:1}".format ("|", "1.查询账户", "2.存款"))
print('\n')
print ("{0:1}{1:<30}{2:>30}{0:1}".format ("|", "3.取款", "4.退出账户"))
print ("=" * 67)
while True:
welcome_user()
NewUser=login_user_check()
if NewUser is None:
continue
while True:
user_interface()
user_key=input('请输入业务操作')
if user_key=='1':
check_balance()
elif user_key=='2':
add_balance()
elif user_key=='3':
draw_balance()
elif user_key=='4':
loginOut()
break