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 Challenge

I cannot seem to get a "FizzBuzz" result. What am I doing wrong?

I have successfully returned Fizz and Buzz, but even with integers 15 and 30 I am not getting. FizzBuzz! Any assistance is appreciated.

name = input("Please enter your name: ")
number = int(input("Please enter a number: "))
print("Hi,",name)
print("Your number is",number,"...")
if number % 3 == 0:
    print(number,"is a Fizz number!")
elif number % 5 == 0:
    print(number,"is a Buzz number!")
elif number % 3 == 0 and number % 5 == 0:
    print(number," is a FizzBuzz number!")
else:
    print(number,"is neither a fizzy or a buzzy number.")

3 Answers

Hi Brianda,

Your statements are written correctly, but the order of the statements is important.

Remember that conditions are evaluated in order and if the condition is true, then it runs the command and your code block ends.

Let's look at your code step by step: First, the computer will check to see if number % 3 == 0. If this is true, the code carries out the print statement and ends.

If the condition is false, then the computer moves to the next line of code and checks if number % 5 == 0. If this is true, the code carries out the print statement and ends.

If these are both false, the computer evaluates the conditions of the next line and so on.

Hope this helps!

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

Your code parses properly, but!

.. be careful ... Python does the comparisons sequentially so you would never see a "FizzBuzz" because it would test as a "Fizz" number first.

Make the "FizzBuzz" test first and it will work.

Thank you both so much! I can't believe I made such a silly error!