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 trialUmair iqbal
910 Pointswhy am i getting a syntax error?
import random
Generate a random number.
secret_num = random.randint(1, 10)
Tell the player if the guess is right or not.
while True: #Allow the player to guess. guess = int(input("What is your guess?:") if guess == secret_num: print("You got it {} was my secret number.".format(secret_num)) break elif guess > secret_num: print("My number is greater than {}.".format(guess)) continue else: print("My number is less than {}.".format(guess)) continue This is my code and i get a syntax error for the line with if guess == secret_num:
2 Answers
Dmitriy Ignatiev
Courses Plus Student 6,236 PointsHi Umair,
it is because you miss ) in print ("My number is less than {}.".format(guess)
You need add ) to the end of above
print("My number is less than {}.".format(guess))
It will works
Cody Munster
1,710 PointsYou've Written:
guess = int(input("What is your guess?:")
Your First error is in the above i think. Try below:
guess = int(input("What is your guess?:"))