我不熟悉编程并尝试在Python中编写不同版本的DiceRoller游戏。方法未定义
我的代码如下,我得到一个doAgain is not defined
错误。
我不确定这是简单的缩进,还是我需要在某处休息一下。
我知道这可能是一个重复,但我仍然有一点点麻烦找到这个确切的问题。
import random
min = 1
max = 6
roll_again = 'yes'
while roll_again == 'yes' or roll_again == 'y':
print 'Rolling the dice...'
print 'The values are...'
print random.randint(min,max)
print random.randint(min,max)
doAgain()
def doAgain():
userInput = raw_input('\nWould you like to roll the dice again? \nYes \nNo')
if userInput == 'Yes':
roll_again
elif userInput == 'No':
print ('Thank you for playing!')
else:
print ('You have entered an incorrect response.')
穿戴'doAgain()'函数之前'while'回路。 –
不是您当前的问题,但请注意,roll_again永远不会更新,因此您的循环将永远持续。 – Foon