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 trialRoss McPherson
774 PointsNumber Game, Program Won't Work!
I have tried countless times to try and figure out why this isn't working!
import random
secret_num = random.randint(1, 10)
while True:
guess = int(input("Guess a number betweeen 1 and 10: ")
if guess == secret_num:
print("You got it! My number was {}".format(secret_num))
break
else:
print("Thats not it")```
I'm getting a syntax error in line 7.
3 Answers
Steven Parker
231,172 PointsIt looks like you're missing a closing parenthesis ")" for the int function on the line above:
guess = int(input("Guess a number betweeen 1 and 10: ")
Ary de Oliveira
28,298 Pointsimport random
secret_num = random.randint(1, 10)
while True:
guess = int(input("guess a number between 1 and 10: "))
if guess == secret_num:
print("you got it! my number was {}".format(secret_num))
break
else:
print("that is not it")
output: Guess a number between 1 and 10: 2
that is not it Guess a number between 1 and 10: 3
that is not it Guess a number between 1 and 10: 4
that is not it Guess a number between 1 and 10: 5
that is not it Guess a number between 1 and 10: 6
that is not it Guess a number between 1 and 10: 7
that is not it Guess a number between 1 and 10: 8
that is not it Guess a number between 1 and 10: 9
that is not it Guess a number between 1 and 10: 1
that is not it Guess a number between 1 and 10: 10
You got it! My number was 10
Randy Helvey
11,311 PointsClose your input statement.