Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Letter Game App Exiting

Simple python question for my homework but just isnt working for me

purpose: expects nothing

returns True if the word in the global variable "secret_word"

has been guessed, based on the "letters_guessed" list

and returns False otherwise

def word_guessed(): ''' Returns True if the player has successfully guessed the word, and False otherwise. ''' global secret_word global letters_guessed

if letters_guessed == secret_word:
    return False
else:
    return True

should look like this but when i run it, its not working

secret_word = "arf" letters_guessed = ['a', 'r', 'f'] word_guessed() True letters_guessed = ['a', 'r'] word_guessed() False

firedoor.py

2 Answers

Your code is in very broad definition. Its hard to tell but the code is wrong from my view. Your function is trying to see if a string is equal to a list. This will always return False (in your case, your function is returning True).

To fix this, you can write the code like this:

word_count = 0

def word_guessed():
    if (letter_guesse in secret_word):
        world_count = word_count + 1
        if (word_count == len(secret_word)):
            return True
    else:
        False

Now the code can work the way you showed on the terminal.

TEST_ID = L M_TEST
TEST_ID = L M_TEST
2,238 Points

Try to turn it around

for word in letters_guessed:
  if word in letters_guessed:
    return True
  else:
    return False