首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python ATM环路故障

python ATM环路故障
EN

Stack Overflow用户
提问于 2014-12-12 22:43:20
回答 1查看 2.1K关注 0票数 0

我已经写了这个程序,似乎不知道如何让程序循环回到开始,并再次询问‘选择’选项。

程序运行良好,所有内容都打印到屏幕上,即使是询问您是否想要另一个事务的部分,我如何使它返回呢?

写自动取款机程序。输入帐户余额,打印开始余额。要求存款或提款,根据选择,调用函数执行他们想要的行动,然后打印新的余额。(使用迭代)

代码语言:javascript
复制
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)")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-12 22:52:40

也许您需要一个循环来重复这个选择:

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27453259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档