# 定义一个用于存客户信息的列表变量,用字典方式
stulist=[
{'name':'zhangsan','ka_id':'111111','password':'111111','balance':888},
{'name':'lisi','ka_id':'222222','password':'222222','balance':999},
{'name':'wangwu','ka_id':'333333','password':'333333','balance':777}
]
#定义验证银行卡号与密码匹配的函数
def check(user_name,user_password):
'''
验证输入的卡号和密码是否正确函数
'''
for i in range(len(stulist)):
if user_name==stulist[i]["ka_id"] and user_password==stulist[i]["password"]:
return i #匹配返回I,否则返回None
#定义用户登录成功后操作界面的函数
def interface():
'''
用户登录成功后操作界面的函数
'''
print("="*14,"用户操作界面","="*14,"\n")
print("{0:2} {1:12} {2:12} {3:12}".format(" ","1. 查询","2. 取款","3. 存款"),"\n")
print("{0:2} {1:10}".format(" ","4. 退出"),"\n")
print("="*42,"\n")
#定义用户查询信息的函数
def inquire(user_id):
'''
用户查询信息的函数
'''
print("="*14,"账号查询界面","="*14,"\n")
print("|{0:<4}|{1:<18}|{2:<9}|\n".format("账户名","卡号","余额(RMB)"))
print("|{0:<5}|{1:<20}|{2:<11}|\n".format(stulist[user_id]["name"],stulist[user_id]["ka_id"],stulist[user_id]["balance"]))
#定义用户取款的函数
def withdrawal(amount):
'''
用户取款的函数
'''
i = stulist[userid]["balance"]-int(amount)
if i>=0:
stulist[userid]["balance"]-=int(amount)
else:
print("账户余额不足\n")
#定义用户存钱的函数
def withadd(amount):
'''
用户存钱的函数
'''
i = stulist[userid]["balance"]+int(amount)
stulist[userid]["balance"]+=int(amount)
#用户登录界面
while True:
# 输出初始界面
print("="*14,"银行取款ATM系统","="*12)
print("{0:2}{1:<15}{2:5}{3:5}".format("","1、登录","2、创建账户","3、退出系统"))
print("*"*40)
key = input("请选择操作选项:")
if key == "1":
print("-"*12,"登录界面","-"*12,)
user_name=input("请输入卡号:")
user_password=input("请输入密码:")
#输入密码后,判断卡号密码是否正确
userid=check(user_name,user_password)
if userid != None:
print("登录成功")
while True:
interface()#调用查询函数
key_word = input("请输入操作选项:")
if key_word=="1":
inquire(userid)
input("按回车键继续:")
print("")
elif key_word=="2":
print("="*14,"账号取款界面","="*14,"\n")
amount = input("请输入取款金额:")
print("")
withdrawal(amount)
inquire(userid)
input("按任意键返回")
elif key_word=="3":
print("="*14,"账号存款界面","="*14,"\n")
amount = input("请输入存款金额:")
print("")
withadd(amount)
inquire(userid)
input("按任意键返回")
elif key_word=="4":
break
input("按回车键继续:")
elif key == "2":
print("-"*12,"添加客户信息","-"*12)
stu={}
stu['name']=input("请输入学员姓名:")
stu['ka_id']=input("请输入客户账号:")
stu['passworda']=input("请输入客户密码:")
stu['balance']=input("请输入金额:")
stulist.append(stu)
input("按回车键继续:")
elif key == "3":
print("-"*12,"退出系统","-"*12,)
break
else :
print("输入的信息有误!")