标签:登录 atm menu 错误 mon money false 查询 else
# 初始化存储变量
cards = [123456, 234567, 345678] # 存放用户卡号
pwds = [111, 222, 333] # 存放用户的密码
moneys = [1000, 1000, 100] # 存放用户的余额
IsLogin = False # 用户是否登录
loginUser = -1 # 登录的用户,保存数组的下标
loginCount = 0 # 登录次数
#主菜单
def menu():
while True :
print("欢迎来到doubleyongATM机存取款机器")
print("1. 查询 2. 存款")
print("3. 取款 4. 转账")
print("5. 退出")
choice = int(input("请输入你的选择:"))
if choice == 1:
chaxun()
elif choice == 2:
cunkuan()
elif choice ==3:
qukuan()
elif choice ==4:
zhuanzhang()
elif choice == 5:
exit()
break
# 登录
def Login():
user = int(input("请输入你的卡号"))
pwd = int(input("请输入你的密码"))
for i in range(0,len(cards)):
if cards == user and pwds == pwd:
global IsLogin
IsLogin = True
global loginUser
loginUser = i
print("登录成功")
menu()
break
#查询
def chaxun():
print(IsLogin)
#先判断用户是否登录
if IsLogin == False :
print("请先登录")
return
print(moneys)
print("你当前的余额为:",moneys[loginUser]);
#存款
def cunkuan():
# 先判断用户是否登录
if IsLogin == False:
print("请先登录")
return
cunMoney = int(input("请输入你要存放的金额"))
moneys[loginUser] = moneys[loginUser] + cunMoney
print("存放成功,当前余额为:",moneys[loginUser]);
def zhuanzhang():
# 先判断用户是否登录
if IsLogin == False:
print("请先登录")
return
usercard = int(input("请输入你要转账的卡号"))
zhangMoney = int(input("请输入你要转账的金额"))
#判断卡号是否存在
zhangCard = -1;
for i in range(0, len(cards)):
if cards == usercard:
zhangCard = i
break
if(zhangCard == -1):
print("你的转账账号不存在")
return
elif int(zhangMoney) > moneys[loginUser]:
print("对不起,你的余额不足")
return
moneys[loginUser] = moneys[loginUser] - zhangMoney
moneys[zhangCard] = moneys[zhangCard] + zhangMoney
print("转账成功,当前余额为:", moneys[loginUser])
#取款
def qukuan():
# 先判断用户是否登录
if IsLogin == False:
print("请先登录")
return
quMoney = int(input("请输入你要取的金额"))
global moneys
if int(quMoney)> moneys[loginUser]:
print ("对不起,你的余额不足")
return
moneys[loginUser] = moneys[loginUser] - quMoney
print("取款成功,当前余额为:",moneys[loginUser])
#退出
def exit():
print("欢迎使用doubleyongATM机,下次再来哦")
IsLogin = False
loginUser = -1
loginCount = 0
while True :
Login()
if (IsLogin == True or loginCount > 2) :
break
else:
loginCount = loginCount+1
if(loginCount==3) :
print("密码错误3次,请到银行柜台找回密码")
标签:登录 atm menu 错误 mon money false 查询 else
原文地址:http://www.cnblogs.com/moriah/p/6661679.html