湾创建一个模拟简单储蓄账户模拟的程序。首先询问用户初始余额(必须至少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.)
答案 0 :(得分:1)
您想错过前一行的)
:
if ans == 1:
deposit = int(input("\n How much would you like to deposit: $"))
和另一个:
withdraw = int(input("\n How much would you like to withdraw: $"))
然后拖尾:
:
if (balance - withdraw) < 0:
另一个)
进一步:
if (balance - withdraw) < 0
withdraw = int(input("\n Tried to withdraw too much! How much would you like to withdraw: $"))
,然后是%
之后的空格(并摆脱.
):
print("Your final balance is %d" % balance)
答案 1 :(得分:0)
你错过了一个&#39;)&#39;在第16行。