Ask the user if they want to repeat the same task again

后端 未结 2 459
渐次进展
渐次进展 2020-11-29 12:57

If the user gets to the end of the program I want them to be prompted with a question asking if they wants to try again. If they answer yes I want to rerun the program.

2条回答
  •  攒了一身酷
    2020-11-29 13:24

    You can enclose your entire program in another while loop that asks the user if they want to try again.

    while True:
      # your entire program goes here
    
      try_again = int(input("Press 1 to try again, 0 to exit. "))
      if try_again == 0:
          break # break out of the outer while loop
    

提交回复
热议问题