while True: #This is an infinite loop. If you want to quit, you can only exit layer by layer. For example, if you enter quit at the third layer, it will return to the second layer. Is there any way to exit all at the third layer? print ( " level1 " ) choice = input( " Please enter your choice: " ) if choice == " quit " : break while True: print ( " level2 " ) choice = input( " Please enter your choice: " ) if choice == " quit " : break while True: print ( " level3 " ) choice = input( " Please enter your choice: " ) if choice == " quit " : break
tag = True while tag: #Assign True to the tag, once the condition is not met, the while loop will not be executed. Remember to print ( " level1 " ) choice = input( " Please enter your choice: " ) if choice == " quit " : break if choice == " quit_all " : tag = False #Add this if condition to each loop while tag: print ( " level2 " ) choice = input("请输入你的选择: ") if choice == "quit": break if choice == "quit_all": tag = False while tag: print("level3") choice = input( " Please enter your choice: " ) if choice == " quit " : break if choice == " quit_all " : tag = False