我目前正在学习Python 3,并且到目前为止,它已经如雨后春笋般涌现。 这个简单的骰子滚子的目标是接受用户输入,是/否,然后掷骰子。如果未达到是/否,则告诉他们答案无效,然后继续提问。
除我无法弄清楚如何接受“是”和“ y”或“否”和“ n”作为答案之外,其他所有方法都很有效。如果我添加或(answery =“ yes”或“ y”),由于某种原因,脚本会将任何答案作为掷骰子。制作列表,具有多个变量(answery1 =“是” answery2 =“ y”),添加逗号(answery =(“ yes”“ y”)等也是一样。
from random import randint
def reroll():
answer = input("Would you like to roll the die again? Yes/No \n")
answer = answer.lower()
answery = "yes"
answern = "no"
if answer == answery:
print(randint(0, 6))
reroll()
elif answer == answern:
print("Thanks for rolling!")
else:
print("That's not an option.")
reroll()
def roll():
answer = input("Would you like to roll the die? Yes/No \n")
answer = answer.lower()
answery = "yes"
answern = "no"
if answer == answery:
print(randint(0, 6))
reroll()
elif answer == answern:
print("Thanks for rolling!")
else:
print("That's not an option.")
roll()
roll()