【发布时间】:2015-10-11 21:48:41
【问题描述】:
b.创建一个模拟简单储蓄账户模拟的程序。首先向用户询问初始余额(必须至少为 100 美元且小于 400,000 美元)。只要用户想继续允许他们进行存款和取款 - 不要透支!用户完成后,输出最终余额。 (建议......使用类似的菜单: 1. 存款 2. 提款 3.退出)
balance = int(input("Enter initial balance: $ "))
while balance <= 100 or balance >= 400000:
print ("Invalid Amount!")
balance = int(input("Ener valid amount: $ "))
deposit = 0
withdraw = 0
if balance >= 100 and balance <= 400000:
while ans != 3:
print("""
1. Deposit
2. Withdrawal
3. Quit
""")
ans = int(input("What would you like to do? Please enter the appropriate number. "))
if ans == 1:
deposit = int(input("\n How much would you like to deposit: $")
balance = balance + deposit
elif ans == 2:
withdraw = int(input("\n How much would you like to withdraw: $")
if (balance - withdraw) < 0
withdraw = int(input("\n Tried to withdraw too much! How much would you like to withdraw: $")
balance = balance - withdraw
elif ans == 3:
print("Your final balance is %d" %balance.)
【问题讨论】:
-
if (balance - withdraw) < 0缺少:。你最后的print语句没有缩进,而且你在balance之后有一个尾随.。 -
余额 = 余额 + 存款时仍然出现错误
-
前一行缺少尾随
)。始终查看上面检测到错误的行。 -
第 19 行还缺少
) -
你在定义之前不使用
ans吗?这将导致 NameError。