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 The Solution: While Loops

Philip Schultz
Philip Schultz
11,437 Points

Why does Kenneth use - if not current %3 or current % 5 == 0:

Hello Everyone, I'm struggling to understand why someone would write the if statement like this

current = 1
while current < 101:
  if not current %3 or current % 5 == 0: 
    print(current)
  current += 1 

Why use 'not current %3' in one half of the if statement, but not the other with %5. I understand using one or the other but isn't it confusing to the reader to use both forms of logic back to back?

For example, he could have said

 if not current %3 or not current % 5: 

or he could have said

 if  current %3 ==0 or  current % 5==0: 

Both of these would give the same result and much easier to read for the user, right? Am I missing something?

2 Answers

I agree. I would stick to using one or the other.

I personally prefer current % 3 == 0, because it makes it clear that you are checking whether the remainder is zero or not. But regardless of which method I use, I would always stick to one or the other. Funny seeing Kenneth do that :grin:

Hey explicitly says he's just demonstrating multiple way to arrive at the same solution, to give us examples of how there are usually several ways to accomplish a task in coding. I don't think he would have left dissimilar approaches in his production code if this was for a real-world application.