我已经写了这个程序,似乎不知道如何让程序循环回到开始,并再次询问‘选择’选项。
程序运行良好,所有内容都打印到屏幕上,即使是询问您是否想要另一个事务的部分,我如何使它返回呢?
写自动取款机程序。输入帐户余额,打印开始余额。要求存款或提款,根据选择,调用函数执行他们想要的行动,然后打印新的余额。(使用迭代)
def withdraw():
amt = int(input("What amount to withdraw - multiples of $20: "))
print('New balance: $', balance - amt)
def deposit():
amt = int(input("How much are you depositing? "))
print('New balance: $',balance + amt)
def bal():
return(balance)
print ("Hello, Welcome to Python ATM.")
balance = float(65.01)
pin = int(input("please enter your account number (Any number:) "))
print('''Current balance: $''',balance)
choice = int(input('''
Please choose an option from the following:
1 - Withdraw
2 - Deposit
3 - Check Balance
4 - Exit: '''))
if choice == 1:
print(withdraw());
elif choice == 2:
print(deposit());
elif choice == 3:
print(bal());
more = input("Would you like another transaction? (y/n)")发布于 2014-12-12 22:52:40
也许您需要一个循环来重复这个选择:
while True:
print('''Current balance: $''',balance)
choice = int(input('''
Please choose an option from the following:
1 - Withdraw
2 - Deposit
3 - Check Balance
4 - Exit: '''))
if choice == 1:
print(withdraw());
elif choice == 2:
print(deposit());
elif choice == 3:
print(bal());
more = input("Would you like another transaction? (y/n)")
if more.lower() != 'y':
print("Goodbay")
breakhttps://stackoverflow.com/questions/27453259
复制相似问题