简体   繁体   中英

How would i loop this bit of code so that It will go to the start again?

I'm a new to python and i need a bit of help. I just need to know how would i loop this bit of code so that after it says "please try again..." it will then go onto "Do you want to roll or stick". Thanks in advance.

Roll = input("Do you want to Roll or Stick?")
if Roll in ("Roll" , "roll"):
    print("Your new numbers are," , +number10 , +number20 , +number30 , +number40 , +number50)
if Roll in ("Stick" , "stick"):
    print("Your numbers are," , +number1 , +number2 , +number3 , +number4 , +number5)
else:
    print("Please try again.")

You can wrap up your code with while loop:

while True:
    Roll = input("Do you want to Roll or Stick?")
    if Roll.lower() == 'exit':
        break
    ...
    else:
        print("Please try again. Type 'exit' to exit.")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM