假设一个简单的ATM机的取款过程是这样的:首先提示用户输入密码(password),
最多只能输入三次,超过3次则提示用户“密码错误,请取卡”结束交易。
如果用户密码正确,再提示用户输入取款金额(amount)。
ATM机只能输出100元的纸币,一次取钱数要求最低100元,最高1000元。
若用户输入的金额符合上述要求,则打印输出用户取得钱数,
最后提示用户“交易完成,请取卡”,否则提示用户重新输入金额。
假设用户密码是111111。
代码如下:
ATM
realpassword = 111111
password = int(input("please enter your password"))
while password == realpassword:
amount = int(input("please enter the amount you want:"))
remainder = amount/100
list = [1,2,3,4,5,6,7,8,9,10]
if remainder < 1:
print("金额过少")
break
if remainder > 10:
print("金额过多")
break
if remainder in list:
print(amount)
print("交易结束,请取卡")
break
else:
print("不符合取的钱数")
break
while password != realpassword:
password = int(input("please enter your password"))
if password != realpassword:
break
else:
amount = int(input("please enter the amount you want:"))
remainder = amount/100
list = [1,2,3,4,5,6,7,8,9,10]
if remainder < 1:
print("金额过少")
break
if remainder > 10:
print("金额过多")
break
if remainder in list:
print(amount)
print("交易结束,请取卡")
break
else:
print("不符合取的钱数")
break
while password != realpassword:
password = int(input("please enter your password"))
if password != realpassword:
print("密码错误,请取卡")
break
else:
amount = int(input("please enter the amount you want:"))
remainder = amount/100
list = [1,2,3,4,5,6,7,8,9,10]
if remainder < 1:
print("金额过少")
break
if remainder > 10:
print("金额过多")
break
if remainder in list:
print(amount)
print("交易结束,请取卡")
break
else:
print("不符合取的钱数")
break
代码截图如下:
代码运行结果如下: