Fizz Junior ๐ฅค
Meet % โ the remainder operator. It doesn't divide, it tells you
what's left over after dividing.
print(7 % 3) # โ 1 (7 = 3 + 3 + 1 left over)
print(9 % 3) # โ 0 (nothing left over!)
print(10 % 5) # โ 0
That zero is the useful bit. If the remainder is 0, it divides evenly โ so this is how you test "is this a multiple of 3?":
if number % 3 == 0:
print("multiple of 3!")
This is a famous job-interview puzzle. Real grown-up programmers get asked this. You're about to smash it. ๐ช
Your mission
Count from 1 to 20, printing one line per number โ except when the
number divides evenly by 3. Then print fizz instead.
So: 1, 2, fizz, 4, 5, fizz, 7, 8, fizz...
Your code
Press โถ Run to see what your code does!