我正在制作一个策划游戏,我刚刚开始并遇到了一个绊脚石。我需要允许用户选择游戏中的钉子数量,然后让用户猜测代码。我正在尝试检查猜测的长度,并确保它与他们选择的钉子数量相同。到目前为止,这是我的代码:
def pegs():
numberOfPegs = input("Please enter the number of pegs in the game between 3 and 8 ")
if numberOfPegs < 3:
return ("Make sure you enter a number between 3 and 8")
elif numberOfPegs > 8:
return ("Make sure you enter a number between 3 and 8")
else:
return ("Thank you, you are playing with", numberOfPegs, "pegs")
def checker():
guess = raw_input("Please enter your guess as letters ")
if len(guess) != pegs:
print "Wrong number!"
else:
return 1
print pegs()
print "\n"
print checker()
并且 checker() 总是返回“错误的数字”,即使我输入的猜测中的字母数量与我选择的钉子的数量相同,我不知道为什么。
谢谢!