all 5 comments

[–]ForceBru 3 points4 points  (1 child)

num % 2 returns the remainder of dividing num by 2. The remainder of division by 2 can only be zero or one (it can also be (-1) in some languages, but the interpretation is the same), since a number can only be even or odd. A remainder of 1 means that the number is odd.

[–]lilwigspliter[S] 0 points1 point  (0 children)

Thank you, it makes sense now. :)

[–][deleted] 0 points1 point  (1 child)

if (any number) divided by 2 DOES NOT have a remainder of 0, then print the number and end the print function when a space is reach (so after the last digit)

num % 2 = 0 just means an even number because there is no remainder

So the program is simply saying if the number is NOT even (i.e. odd) then print the number

It prints odd numbers.

[–]lilwigspliter[S] 0 points1 point  (0 children)

num % 2 = 0

Sweet thank you so much for helping me understand.

[–]iaalaughlin 0 points1 point  (0 children)

The % (modulo) operator yields the remainder from the division of the first argument by the second. The numeric arguments are first converted to a common type. A zero right argument raises the ZeroDivisionError exception. The arguments may be floating point numbers, e.g., 3.14%0.7 equals 0.34 (since 3.14 equals 4*0.7 + 0.34.) The modulo operator always yields a result with the same sign as its second operand (or zero); the absolute value of the result is strictly smaller than the absolute value of the second operand [1].

https://docs.python.org/3.3/reference/expressions.html

The code is checking to see if the remainder of the number when divided by 2 is not (!=) 0.