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

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
229,005 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")

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
229,005 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.