Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python程序,如何使atm程序循环_Python_Loops - Fatal编程技术网

Python程序,如何使atm程序循环

Python程序,如何使atm程序循环,python,loops,Python,Loops,这样做之后,我如何使它回到起点?每次交易结束后,它都会结束,不会返回查看您是否可以选择其他选项。 谢谢,非常感谢 balance=7.52 print("Hi, Welcome to the Atm.") print("no need for pin numbers, we already know who you are") print("please selection one of the options given beneath") print(""" D = Deposit

这样做之后,我如何使它回到起点?每次交易结束后,它都会结束,不会返回查看您是否可以选择其他选项。 谢谢,非常感谢

balance=7.52
print("Hi, Welcome to the Atm.")
print("no need for pin numbers, we already know who you are")
print("please selection one of the options given beneath")
print("""
    D = Deposit
    W = Withdrawal
    T = Transfer
    B = Balance check
    Q = Quick cash of 20$
    E = Exit
    Please select in the next line.   
""")
option=input("which option would you like?:")
if option==("D"):
    print("How much would you like to deposit?")
    amount=(int(input("amount:")))
    total=amount+balance
elif option ==("W"):
    print("How much would you like to withdrawl?")
    withdrawl=int(input("how much would you like to take out:?"))
    if balance<withdrawl:
        print("Error, insufficent funds")
        print("please try again")
elif option == "T":
    print("don't worry about the technicalities, we already know who you're          transferring to")
    transfer =int(input("How much would you like to transfer:?"))
    print("you now have", balance-transfer,"dollars in your bank")
elif option=="B":
    print("you currently have",balance,"dollars.")
elif option=="Q":
    print("processing transaction, please await approval")
    quicky=balance-20
    if balance<quicky:
         print("processing transaction, please await approval")
    print("Error, You're broke.:(")
elif option=="E":
      print("Thanks for checking with the Atm")
      print("press the enter key to exit")

看起来你是在问一个循环

在打印菜单之前的某个地方,设置sentinel值:

keep_going = True
然后,最好在下一行打印循环时要看到的第一件东西之前,启动循环

while keep_going:   # loop until keep_going == False
如前所述,这是一个无限循环。while语句下面缩进块中的所有内容都将按顺序永远重复。这显然不是我们想要的——我们必须有办法出去,这样我们才能用我们的电脑做其他事情!这就是我们的哨兵进来的地方

内置一个新的菜单选项,允许用户退出。假设您将其输入到Q,然后用户选择它。然后,在该分支中:

elif option == 'Q':
    keep_going = False
因为这就是该分支中的全部内容,我们从循环的底部掉下来,然后返回while语句,它现在无法通过检查。循环终止

顺便说一下,你应该考虑阅读。它非常容易阅读,并让您了解如何使代码也非常容易阅读。大多数Python程序员都遵守它,并期望其他人也这样做,所以您也应该这样做!如果你想帮助你学习它,或者不确定你做得是否正确,那么有很多方法可以帮助你保持它的整洁和无错误


快乐编程

我知道它没有正确缩进,我是这个网站的新手,我不知道如何正确缩进。这里的提问者应该具备编程的基本工作知识,并且已经完成了关于一个问题的家庭作业。如何循环?这是一个基本的,大学课程的第一个主题,它基本上违反了这两个类别。对不起,我这样做是为了消遣,我在高中,只是个新手。相当严厉的批评,请不要把它当回事。我只是想解释一下我的否决票和其他可能会发生的事情。你没有足够的代表聊天,或者我会和你聊天,所以我至少会看看你的代码。这是伟大的,你正在学习,所以不要气馁;如果你在这里没有得到最好的帮助,也不要感到惊讶。不管是好是坏,这不是这个网站真正的功能。我也在上高中,但我已经为Python和Java编程好几年了,所以我会给你一些建议。您需要修正缩进以反映不同的案例及其后续语句。另外,使用while循环,直到达到所需的情况。非常感谢!我一定会用导游来启发自己的