python - TypeError: object of type 'builtin_function_or_method' has no len(), in 2 parts of the code -


i'm working on hangman game, , keep running same error, , i've been trying debug couple hours no progress.

this error message:

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() 

here relevant parts of code:

line 98 - 110

`def guessletter(previousguess):   #this function lets player guess letter, , see if guess acceptable     while true:         print ('guess letter')         guess = input()         guess = guess.lower              if len(guess) != 1:             print ('enter single letter please.')         elif guess in previousguess:             print ('that letter guessed. choose another')         elif guess not in 'abcdefghijklmnopqrstuvwxyz':             print ('please put letter')         else:             return guess` 

line 125~141

while true: board(hangmanpictures, miss, correct, unknownword)   #i define board function @ top  guess = guessletter(miss + correct)   #i use function defined above, seems make error here..  if guess in unknownword:     correct = correct + guess      foundallletters = true    #check if player has won     k in range(len(unknownword)):         if unknownword[k] not in correct:             foundallletters = false             break      if foundallletters:         print ('the secret word "' + unknownword + '"! won!')         gamefinish = true 

the problem line:

guess = guess.lower 

you forgot call str.lower method guess being assigned method object itself.

to fix problem, call method placing () after name:

guess = guess.lower() #                  ^^ 

below demonstration:

>>> guess = 'abcde' >>> guess = guess.lower >>> guess <built-in method lower of str object @ 0x014fa740> >>> >>> guess = 'abcde' >>> guess = guess.lower() >>> guess 'abcde' >>> 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -