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 trialnafiz hassan
11,482 PointsUnexpected 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:
try:
# 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))
else:
# compare guess to secret number
if guess == secret_num:
print ("You get it! My number was {}".format(secret.num))
break
else:
print ("That's not it!")
guesses.append(guess)
# print hit/miss
game()
[MOD: added ```python formatting -cf]
2 Answers
Abdishakur Hassan
3,585 PointsYou 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=
nafiz hassan
11,482 PointsThanks guys... missed parenthesis was the issue now its resolved and "<line 18>" was for the forum
Christopher Janke
11,054 PointsChristopher Janke
11,054 Pointsguess = 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?