Python 3.x 将一个程序循环回到开始?
嗨,我正在写一个掷骰子的程序,想知道如何在程序结束时将其循环到程序的开头。任何解决方案都将受到高度重视。谢谢Python 3.x 将一个程序循环回到开始?,python-3.x,Python 3.x,嗨,我正在写一个掷骰子的程序,想知道如何在程序结束时将其循环到程序的开头。任何解决方案都将受到高度重视。谢谢 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 i
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)
将允许玩家选择模具类型并无限次显示分数(除非宇宙热死、Ctrl-C或设备或电源故障)您是否尝试将您的语句包装在另一个while循环中?将所有内容包装在while True循环中。只需编写
而为True:
在导入随机
下,并缩进它下面的所有内容。是的,我已经尝试过了,它只是破坏了程序。
import random
while True:
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)