嗨,我正在寫一個骰子滾動程序,並想知道如何將其循環回到最後的程序開始。任何解決方案都將大大降低。由於循環程序回到開始?
import random
while True:
dice_type = int(input("would you like to roll a 4,6 or 12 sided dice:"))
if dice_type in [4, 6, 12]:
break
print("Sorry that is not the correct input")
score = random.randint(1, dice_type)
print ("You have chosen to throw a %d-sided dice" %dice_type)
print ("You rolled a %d" %score)
你有無限多嘗試在另一個while循環中包裝你的語句? –
我該怎麼做? –
將所有內容都包裹在True循環中。只需在'import random'下寫'While True:'並在其下面縮進一切。 – Tobberoth