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

Python Comparison Solution

Mark Roudebush
Mark Roudebush
901 Points

Error in presented solution

When I use the presented solution here in this video I get an error that I can't resolve. Unfortunately, Craig never runs the solution he's showing so we don't see this error. I believe I copied his solution verbatim but get this:

File "challenge.py", line 24
is_fizz = number % 3 == 0
^
SyntaxError: invalid syntax

Mark Roudebush
Mark Roudebush
901 Points
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."
# *********************


# 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.
is_fizz = number % 3 == 0
is_buzz = number % 5 == 0:


# Using the variables, check the condition of the value, and print the necessary
# string

if is_fizz and is_buzz:
       print("is a FizzBuzz number.")
elif is_fizz:
       print("is a Fizz number.")
elif is_buzz:
       print("is a Buzz number.")
else:
    print("is neither a fizzy or a buzzy number."

5 Answers

Charlie Krell
Charlie Krell
2,184 Points

Good afternoon,

It looks like there are just ending parentheses missing on two lines, line 9 should read:

print ("Hey, {}! \nThe number {}...".format(name, number))

Then, line 38 should read:

print("is neither a fizzy or a buzzy number.")
Ryan Jaccard
Ryan Jaccard
2,504 Points

Also, looks like there's an unnecessary colon : at the end of line 25

is_buzz = number % 5 == 0:

I'm having the same issue but its different error that pops up

File "challenge.py", line 4
number = int(number)
^
SyntaxError: invalid syntax

name = input("Please enter your name: ")
number = (input("Please enter a number: ")

number = int(number)
print("Hey {}!\nThe number {}...".format(name, number))

is_fizz = number % 3 == 0:
is_buzz = number % 5 == 0:
   if is_fizz and is_buzz:
        print("is a FizzBuzz number.")
   elif is_fizz:
        print("is a Fizz number.")
   elif is_buzz:
        print("is a Buzz number.")
   else: 
        print("is neither a fizzy or buzzy number.")

Hey, it's been a little while since you posted your last question but I wanted to help you out in case you were still stuck or confused on this one. It looks like the error is on the line previous to the syntax error you received.

name = input("Please enter your name: ")
number = (input("Please enter a number: ")

number = int(number)

Take a look at how you're defining number on second 2. Compare it to line 1.

Hope that helps!