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 trial
Christopher Wommack
3,983 Pointsguessing_game_2.py
import random
import sys
def game():
'''Guess a number between 1 and 10
'''
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 == num:
print"You got it my number was {}".format(num)
break
elif guess > num:
print"My number is lower than your guess of {}".format(guess)
guesses.append(guesses)
elif guess < num:
print"My number is higher than your guess of {}".format(guess)
guesses.append(guesses)
else:
print"You didn't guess my number. My number was {}".format(num)
play_agnain = input("Do you want to play again? Y/n")
if play_agnain != 'n':
game()
else:
print"Bye!"
sys.exit()
game()
Getting invalid syntax line 15
2 Answers
john larson
16,594 PointsIt looks like you left the parenthesis of most (if not all) your print functions.
print"{} is not a number.".format(guess)
# should be
print("{} is not a number.".format(guess))
I found three like that and figure if you find and fix those hopefully it should work
Kenneth Love
Treehouse Guest TeacherWhatever program on your computer is saying the parentheses isn't necessary must be running Python 2. In Python 3, they are most definitely required. (I'm betting Codecademy doesn't use Python 3 either, tsk tsk ;) )
Christopher Wommack
3,983 PointsChristopher Wommack
3,983 PointsThanks my program on my computer keeps saying parenthesis unnecessary I don't know why tho My program works with the parenthesis
john larson
16,594 Pointsjohn larson
16,594 PointsYea, that parenthesis thing. On codecadamy their python course runs without parenthesis, I think in the console things will run without parenthesis. But in my regular editors I always have to use parenthesis. What program do use that tells you print() parenthesis are not necessary? Cause that would be fine except your program wasn't running.