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 trialSean Flanagan
33,235 PointsSyntaxError
Hi.
I got the above error.
My code:
name = input("Please enter your name: ")
number = input("Please enter a number: ")
# TODO: Make sure the number is an integer
number = int(number)
# TODO: Print out the user's name and the number entered,
# making sure the two statements are on separate lines of output.
print("Hey {}!\nThe number {}...".format(name, number)
# TODO: Compare the number the user gave with the different
# FizzBuzz conditions.
# *********************
# If the number is divisible by 3, print "is a Fizz number."
# If the number is divisible by 5, print "is a Buzz number."
# If the number is divisible by both 3 and 5, print "is a FizzBuzz number."
# Otherwise, print "is neither a fizzy or a buzzy number."
# *********************
if (number % 3)
print(number + " is a Fizz number.")
elif (number % 5)
print(number + " is a Buzz number.")
elif (number % 3) & (number % 5)
print(number + " is a FizzBuzz number.")
else
print(number + " is neither a fizzy nor a buzzy number.")
# TODO: Define variables for is_fizz and is_buzz that stores
# a Boolean value of the condition. Remember that the modulo operator, %,
# can be used to check if there is a remainder.
# Using the variables, check the condition of the value, and print the necessary
# string
Error:
File "challenge.py", line 20
print(number + " is a Fizz number.")
^
SyntaxError: invalid syntax
2 Answers
KRIS NIKOLAISEN
54,972 PointsSome things to look at:
1) Missing closing parenthesis for print statement here
print("Hey {}!\nThe number {}...".format(name, number)
2) If, elif, else statements should end in a colon
3) Fizzbuzz should be tested as the first condition (try 15 with %3 as the first condition)
4) Integers and strings can't be concatenated in Python without conversion. Ex:
print(str(number) + " is a FizzBuzz number.")
5) I had to explicitly compare the modulo result to 0 though not sure why. Ex:
elif (number%3==0):
Sean Flanagan
33,235 PointsI think the 0 in number & 3 == 0
is the remainder.
Thank you!
Sean Flanagan
33,235 PointsThe order of Ken Alger's instructions confused me. He lists the if statements and then tells us to define the variables.