我创建了一个程序,让用户输入他们想要的骰子并且它可以工作但是我不知道如何获得它所以它会再次询问
import random
while True:
rollagain="yes"
print("your dices available to you are a 4 sided dice a 6 sided dice and a 12 sided dice")
dice=input("which sided dice would you like to roll")
if dice =="4":
dicenumber=random.randint(1,4)
print("dice rolled ",dice,"and number rolled is",dicenumber,)
elif dice =="6":
dicenumber=random.randint(1,6)
print("dice rolled ",dice,"and number rolled is",dicenumber,)
elif dice =="12":
dicenumber=random.randint(1,12)
print("dice rolled ",dice,"and number rolled is",dicenumber,)
elif dice != "4" or dice != "6" or dice != "12":
print ("this dice is not available please choose one available")
rollagain=input("would you like to roll again? if you do enter yes, if not enter no.")
print("thank you for playing")
break
有人可以帮忙吗?
答案 0 :(得分:0)
def get_choice(prompt,choices):
val = raw_input(prompt):
if val not in choices:
print "Invalid Solution! Please Enter %s or %s"%(", ".join(choices[:-1]),choices[-1])
return get_choice(prompt,choices)
return val
print "You entered :",get_choice("Select Dice Type:","4 6 8 12".split())
只要他们在1000次错误之前就做对了,这应该可行