Exercise:
import easygui as g
card1_num = "1001"
card1_pwd = "123456"
card1_money = 0
card2_num = "1002"
card2_pwd = "234567"
card2_money = 100
times = 0
while True:
card = g.multpasswordbox("Please input card number and pin",title = "Banking System",fields = ("Card Number","PIN"))
money = 0
flag = 0#标记
if card == [card1_num,card1_pwd]:
money = card1_money
flag == 1
g.msgbox("Login Successfully.",title = "Banking System")
elif card == [card2_num,card2_pwd]:
flag = 2
money = card2_money
g.msgbox("Login Successfully.",title = "Banking System")
else:
times += 1
if times == 3:
g.msgbox("You have entered wrong password for 3 times. Please contact with the Bank Admin.",title = "Banking System")
pwd = ""
while pwd != "888888":
pwd = g.passwordbox("Please input Admin's password:",title = "Banking System")
times = 0
else:
g.msgbox("Login failed. Please re-enter:", title="Banking System")
continue
while True:
operation = g.buttonbox("Please pick your operation", choices=("Deposit", "Withdraw", "Balance", "Quit"))
if operation == "Quit":
times = 0
if flag == 1:
card1_money = money
elif flag == 2:
card2_money = money
break
elif operation == "Deposit":
save_money = g.integerbox("Please how much will you deposit:", lowerbound=0, upperbound=1000000)
money = money + save_money
g.msgbox("Deposit successfully. Money deposit is " + str(save_money))
elif operation == "Withdraw":
get_money = g.integerbox("Please input how much will you withdraw.", lowerbound=0, upperbound=1000000)
if get_money > money:
g.msgbox("Sorry no enough balance. Operation failed.")
else:
money = money - get_money
g.msgbox("Withdraw successfully. Money withdrew is " + str(get_money))
elif operation == "Balance":
g.msgbox("Your balance is " + str(money))
[…] 24 nested loop| |____Unit 25 Pycharm and turtle| |____Unit 26 mimic banking system I| |____Unit 27 mimic banking system II| |____Unit 28 Perpetual Calendar I| |____Unit 29 Perpetual Calendar II|____Python Level 4| […]