0

Here is the function in question:

def single_letter_guess(guess,word):
    global guessed_letters
    global lives_remaining
    if word.find(guess) == -1:
        guessesLeft -= 0
    guessed_letters = guessed_letters + guess.lower()
    if all_letters_guessed(word):
        return True
    return False

The error is coming from the fourth line and displays :

if word.find(guess) == -1:
AttributeError: 'function' object has no attribute 'find'

I'm still pretty new to python and don't really know how to interpret this error message. It should technically be looking for the guessed letter in the string word. I can provide the full code if needed for more context.

1
  • 1
    It appears that word is a function. How are you calling this function? Commented Oct 29, 2014 at 8:13

1 Answer 1

1

In your function word is a function that is passed in so word.find(guess) is causing your error. word should be a string if you want to use find

I think you may be missing parens somewhere you have set word = some_function so you set word equal to the function and not the return value.:

In [10]: def foo():
   ....:         return "foo"
   ....: 

In [11]: word = foo # no parens

In [12]: print(word.find("f"))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-9db996b190ed> in <module>()
----> 1 print(word.find("f"))

AttributeError: 'function' object has no attribute 'find'

In [13]: word = foo()

In [14]: print(word.find("f"))
0
Sign up to request clarification or add additional context in comments.

1 Comment

That was it. I forgot a paren in an earlier function that defined word. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.