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

I don't understand why we define variables for is_fizz and is_buzz.

Can someone please explain this part? The TODO asks us to define variables for is_fizz and is_buzz that stores a Boolean value of the condition. Also, why do we need the modulo operator?

This challenge was very confusing and difficult.

2 Answers

Josh Keenan
Josh Keenan
19,428 Points

So these two variables will store the output from

is_fizz = number % 3 == 0
is_buzz = number % 5 == 0

These are either going to be True, or False.

is_fizz will evaluate, when the number is divided by 3, is there no remainder, if there is no remainder, I am True, otherwise I am False. The modulo operator divides and keeps the remainder, so if number is 6, is_fizz is true, is_buzz is false, 15 would give True and True, 16 would give False, False.

Feel free to ask any other questions

Also I see you have lots of questions, I'd advise you slow down with the content and don't just view it, go over it again and again as you need to learn and absorb this information, it takes time and effort. You got this!

Roman Schenk
Roman Schenk
1,857 Points

You don't need to understand why they defined those variables as there is no need for them. They did it probably to make you code more and use more of the things you learned. number_int = int(number)

output = "" if (number_int % 3) == 0: output += "Fizz" if (number_int % 5) == 0: output += "Buzz" if not bool(output): output = "is neither a fizzy or a buzzy number."


This would work as well. All you do with the variables is to store the result, where as here it get's lost.