Need help adding a loop to restart program in Python

后端 未结 3 1526
臣服心动
臣服心动 2021-01-28 08:36

So far this is what I have got.

import random

answer1=(\"Absolutely!\")
answer2=(\"No way Pedro!\")
answer3=(\"Go for it tiger.\")
answer4=(\"There\'s different         


        
3条回答
  •  旧时难觅i
    2021-01-28 08:59

    after the import line add while True: indent the entire code to the while loop. then at the end go like this:

        restart = input("Would you like to try again?")
    
        if restart == "yes":
            continue
        else:
            break
    

    To explain further. Continue will jump back up to the top pass would work as well. break will exit the loop. good luck!

提交回复
热议问题