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

Audrey Zzzz
Audrey Zzzz
760 Points

Why does this code result in 3 being called neither a fizzy nor a buzzy number?

is_fizz = number % 3 == 0

is_buzz = number % 5 == 0

if is_fizz == 0 and not is_buzz:

print ("is a Fizz number.")

1 Answer

Steven Parker
Steven Parker
230,917 Points

Some of the code appears to be missing, but assuming "number" begins as 3, then:
is_fizz = number % 3 == 0 :point_left: this will assign "is_fizz as True, and
is_buzz = number % 5 == 0 :point_left: this will assign "is_buzz as False, then
if is_fizz == 0 and not is_buzz: :point_left: since True is not equal to 0, this test will fail.

While the result of comparing booleans to numeric values is reliable, it can result in confusing code. It's much better to test booleans directly (or inverted with "not", as you did with is_buzz). So a fix (and a better test) here would be:

if is_fizz and not is_buzz:
    print ("is a Fizz number.")

For future questions, take a look at this video about sharing a snapshot of your workspace. That lets you share your entire code (including multiple files) just by posting a link. And when you do post code directly, take a look at this one about using Markdown formatting to preserve the code's appearance.