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!

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


Unexpected Syntax Error(except)

Getting a syntax error at line 18, couldn't figure out why. run the script a couple of times

import random 

def game():
    # generate a random number between 1 and 10
    secret_num = random.randint(1, 10)
    guesses= []

    while len(guesses) < 5: 
            # get a number guess from the player
            guess = int(input("Guess a number between 1 and 10: ")
        except ValueError:  <line 18> 
            print ("{} isn't a number!".format(guess))

            # compare guess to secret number 
            if guess == secret_num:                
                 print ("You get it! My number was {}".format(secret.num)) 
                 print ("That's not it!")
            # print hit/miss


[MOD: added ```python formatting -cf]

Christopher Janke
Christopher Janke
11,054 Points

guess = int(input("Guess a number between 1 and 10: ") is missing a )

is <line 18> in your code? Or are you just marking line 18 for the forum?

2 Answers

Abdishakur Hassan
Abdishakur Hassan
3,585 Points

You have this thing in your code next to exceptValueError <line 18> . Remove that and see if it works. And one More paranthesis is missimg before that in Guess=

Thanks guys... missed parenthesis was the issue now its resolved and "<line 18>" was for the forum