How To Make a Python Program Automatically Restart Itself

后端 未结 5 1760
一生所求
一生所求 2020-12-08 11:51

How do you make a python program automatically restart itself? So let\'s say there is a really simple program like:

    var = input(\"Hi! I like cheese! Do y         


        
5条回答
  •  一向
    一向 (楼主)
    2020-12-08 12:27

    You can wrap something in while True: to make it execute repeatedly, as True will always evaluate to True, like this:

    while True:
        var = input("Hi! I like cheese! Do you like cheese?").lower() # <-- You had missed parentheses here        
        if var == "yes":
            print("That's awesome!")
    

    There's another issue with your code though; you haven't called lower by putting parentheses after it.

提交回复
热议问题