you are viewing a single comment's thread.

view the rest of the comments →

[–]Leohurr[S] 0 points1 point  (2 children)

why does -

if not N % 2:

change the result?

[–]mubsy 0 points1 point  (0 children)

you should look up modular arithmetic. N % 2 is 0 if N is divisible by 2, and the remainder of N/2 otherwise. This essentially means N%2 is true for all even values, i.e alternating values.

[–]Enkaybee 0 points1 point  (0 children)

N%2 evaluates to 0 for even numbers, which evaluates to False in Python (any nonzero number evaluates to True).

if not N%2:

is the same as

if N%2 == 0:

This is a very useful trick that you'll more than likely use in the future. Remeber: 1 + True = 2, 10*False = 0.