Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Comparison Solution

Dejuan Castro
Dejuan Castro
198 Points

Does this mean %3 ==0 no remainders ?

So, in this practice problem I think I'm misunderstanding % (percent sign). is_fizz = number %3 == 0 Since the goal is to say fizz if it's divisible by 3 . Why wouldn't we put is_fizz = number /3 ???

1 Answer

From the docs

The % (modulo) operator yields the remainder from the division of the first argument by the second

So if the remainder of the first number divided by the second is zero the first number is perfectly divisible by the second. That is the goal for the fizzbuzz challenge. number /3 will only equal zero if number is zero. This doesn't show you anything since every number is divisible by every number (unless you want to exclude division by zero). If number is positive then number/3 is positive and comparing to zero will always be false.

For example 21 divided by 3 is 7 with no remainder (or remainder = 0).

21%3 == 0 is the same as 0 == 0 and would evaluate to true

21/3 == 0 is the same as 7 == 0 and would evaluate to false