我正在做一个刽子手游戏,我一直遇到同样的错误,我已经试着调试了几个小时,没有任何进展。在
以下是错误消息:
Traceback (most recent call last):
File "hangman.py", line 128, in <module>
guess = guessletter(miss + correct)
File "hangman.py", line 103, in guessletter
if len(guess) != 1:
TypeError: object of type 'builtin_function_or_method' has no len()
以下是我的代码的相关部分:
98-110号线
^{pr2}$while True:
board(hangmanpictures, miss, correct, unknownword) #i define a board function at the top
guess = guessletter(miss + correct) #i use the function defined above, but it seems to make an error here..
if guess in unknownword:
correct = correct + guess
foundallletters = True #check if player has won
for k in range(len(unknownword)):
if unknownword[k] not in correct:
foundallletters = False
break
if foundallletters:
print ('The secret word is "' + unknownword + '"! You won!')
gamefinish = True
问题在于这条线:
您忘记调用
str.lower
方法,因此guess
被分配给方法对象本身。在{cd3>调用该方法修复问题:
^{pr2}$下面是一个演示:
^{3}$相关问题 更多 >
编程相关推荐