Loops 如何返回到Python循环的顶部
我需要一些关于在python中返回循环顶部的帮助,我知道break语句,但我不知道它是否有帮助 这是我的密码:Loops 如何返回到Python循环的顶部,loops,python-3.x,if-statement,Loops,Python 3.x,If Statement,我需要一些关于在python中返回循环顶部的帮助,我知道break语句,但我不知道它是否有帮助 这是我的密码: import random Which_Dice= input("What dice do you want? 4,6 or 12") if input(Which_Dice)!=("4","6","12"): print("Please input the number 4,6 or 12") elif int(Which_Dice)== 4: print(in
import random
Which_Dice= input("What dice do you want? 4,6 or 12")
if input(Which_Dice)!=("4","6","12"):
print("Please input the number 4,6 or 12")
elif int(Which_Dice)== 4:
print(int(Which_Dice), "sided dice thrown", "score",random.randint(0,5))
elif int(Which_Dice)== 6:
print(int(Which_Dice), "sided dice thrown", "score",random.randint(0,7))
elif int(Which_Dice)==12:
print(int(Which_Dice), "sided dice thrown", "score",random.randint(0,13))
代码中没有循环,但这可能会有所帮助
def callme():
Which_Dice= input("What dice do you want? 4,6 or 12")
.
.
callme()
callme()
或者查看for或while循环。如果您想反复运行程序的该部分(有效地跳回到顶部),您可以使用while true循环来完成:
import random
while True:
Which_Dice= input("What dice do you want? 4,6 or 12")
if input(Which_Dice)!=("4","6","12"):
print("Please input the number 4,6 or 12")
elif int(Which_Dice)== 4:
print(int(Which_Dice), "sided dice thrown", "score",random.randint(0,5))
elif int(Which_Dice)== 6:
print(int(Which_Dice), "sided dice thrown", "score",random.randint(0,7))
elif int(Which_Dice)==12:
print(int(Which_Dice), "sided dice thrown", "score",random.randint(0,13))
嗯,代码中没有循环,所以不能“返回到循环的顶部”。