TypeError:类型为“builtin”的对象在cod的2个部分中没有len()

2024-09-29 23:33:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个刽子手游戏,我一直遇到同样的错误,我已经试着调试了几个小时,没有任何进展。在

以下是错误消息:

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}$

125~141号线

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

Tags: inpytruelenif错误functionfile
1条回答
网友
1楼 · 发布于 2024-09-29 23:33:28

问题在于这条线:

guess = guess.lower

您忘记调用str.lower方法,因此guess被分配给方法对象本身。在

{cd3>调用该方法修复问题:

^{pr2}$

下面是一个演示:

^{3}$

相关问题 更多 >

    热门问题