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 Challenge

Arnon Pilz
Arnon Pilz
198 Points

Already know its not the smartest most efficient way but why isn't it working?

name = input("Please enter your name: ") number = int(input("Please enter a number: ")) print("{} \n\n{}".format(name, number)) if number%3: print("is a Fizz number") else: print("mistake")

only for test

2 Answers

Steven Parker
Steven Parker
215,940 Points

When posting code, use Markdown formatting to preserve the code's appearance including indentation (crucial in Python!). You may also want to take a look at this video about Posting a Question.

If you want to determine if a number is divisible by 3, you should test for the remainder to not be truthy; since only when the remainder is 0 will the number be divisible. So:

if not number%3:                # <-- notice the NOT
    print("is a Fizz number")
Arnon Pilz
Arnon Pilz
198 Points

But can it work in a "positive" way? if the number is dividable by 3 - it should print("is a Fizz number") what's the purpose of the "not"?

Steven Parker
Steven Parker
215,940 Points

Remember that "%" is the remainder operator, and having a remainder is the opposite of being evenly divisible. The "not" makes it true when is is divisible.