我写了一个掷骰子游戏,但当我得到一个问题“你想再次掷骰子吗?”我说“不”,无论如何它都会滚。我猜这与answer
变量有关。不过,我希望它打印“也许下次”代替。你能帮助我吗?这是我的密码:
import random
def response():
if answer == "yes" or answer == "Yes" :
rolldice()
else:
print("Maybe next time!")
def rolldice():
randomnumb = random.randrange(1,7)
print("You got number " + str(randomnumb) + "!")
answer = input("Would you like to roll the dice again? \n ")
response()
answer = input("Would you like to roll the dice? \n")
response()
试试这个。必须将answer作为参数传递给函数response:
相关问题 更多 >
编程相关推荐