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 Letter Game Refinement

Eli Cobler
Eli Cobler
892 Points

What is causing the invalid syntax error in this function?

While doing this excerise of the Python Basics course here on Team Tree house I have run into an error that I can't seem to solve. I keep getting this error when trying to fun the script:

treehouse:~/workspace$ python letter_game.py                                                     
  File "letter_game.py", line 50                                                                 
    if len(guess) !=1:                                                                           
                     ^                                                                           
SyntaxError: invalid syntax  

I have tried multiple things with no success. Here is what the function I actually typed out contains. Maybe I am just missing something really simple.

def get_guess(bad_guesses, good_guesses):
    while True:
        guess = input("Guess a letter: ".lower()

        if len(guess) !=1:
            print("You can only guess single letter!")            
        elif guess in bad_guesses or guess in good_guesses:
            print("You've already guessed that letter!")            
        elif not guess.isalpha():
            print("You can only guess letters!")         
        else:
            return guess

Any help anyone can provide would be greatly appreciated!

1 Answer

Steven Parker
Steven Parker
229,644 Points

You're missing a symbol.

On this line:

        guess = input("Guess a letter: ".lower()

It looks like you're missing a close parenthesis after the string and before .lower. The system doesn't become aware of the error until it reaches the end of the following line.