简体   繁体   English

python ATM循环问题

[英]python ATM loop trouble

I have written this program and cant seem to figure out how to get the program to loop back to the beginning and ask the 'choice' option again. 我已经编写了该程序,似乎无法弄清楚如何使该程序循环回到开始并再次询问“选择”选项。

The program runs fine, everything prints to the screen, even the part that asks if you would like another transaction, how do I get this to loop back? 程序运行良好,所有内容都打印到屏幕上,即使是询问您是否要进行另一笔交易的部分,我该如何将其循环返回?

Write ATM program. 编写ATM程序。 Enter account balance, print beginning balance. 输入帐户余额,打印期初余额。 ask for deposit or withdrawl, depending on selection, call function to perform the action they wish, then print new balance. 要求存款或取款,具体取决于选择,调用功能以执行所需的操作,然后打印新的余额。 (Use iteration) (使用迭代)

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)")

Maybe you need a loop to repeat the choice : 也许您需要循环以重复选择:

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")
        break

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM