6/19 n % 3 == 0?


#1

This was partly covered in an earlier 6/19 post.

If I divide something by 3 the answer is never 0. so how is n % 3 == 0 every a thing to test?
% is divide, right?
== is exactly equal to, right?
what am I missing?

if number % 3():
3 is not a function.
if number % 3 == 0:
now becomes a conditional. If the modulo of a number divided by another number is zero, then the divisor is a factor of the dividend.
if A % B == 0:
# A is evenly divisible by B


#2

no, / is for division. % calculates the remainder


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.