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

Maor Beeri
2,154 PointsI get a syntax error to my else statement that points to print("my number is less than {}".format(guess))
import random
def game(): secret_num = random.randint(1,10) guesses = []
while len(guesses) < 5:
try:
guess = int(input("Guess a number between 1 and 10: "))
except ValueError:
print("{} is not a number".format(guess))
else:
if guess == secret_num:
print("Yay you are correct, my number was {}".format(secret_num))
break
elif guess < secret_num:
print("my number is greater than {}".format(guess)
else:
print("my number is less than {}".format(guess))
guesses.append(guess)
else:
print("you didn't get it my number was {}
".format(secret_num))
play_again = input("Do you want to play again? Y/n")
if play_again.lower() != n:
game()
else:
print(" Good Bye!)
game()
2 Answers

Steven Parker
225,664 PointsThe actual issue is a few lines above.
This print statement is missing a closing parenthesis:
print("my number is greater than {}".format(guess)
Also, the string in this statement is missing a closing quote:
print(" Good Bye!)

Maor Beeri
2,154 PointsThanks again

Maor Beeri
2,154 Pointssorry but I get indentation error here:
play_again = input("Do you want to play again? Y/n")
what's the cause of this

Steven Parker
225,664 PointsThe code you see above has not been formatted to display correctly using Markdown, so you're not seeing the actual indentation.
Maor Beeri
2,154 PointsMaor Beeri
2,154 Pointsthank you very much! although I still get an error in this line: play_again = input("Do you want to play again? Y/n")
(by the way, how do you copied my code lines in such a nice way? :) )
Steven Parker
225,664 PointsSteven Parker
225,664 PointsYou may also need to reconstruct the string that appears split above into a single line:
print("you didn't get it my number was {}".format(secret_num))
And use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area.
Or watch this video on code formatting.