EasyPython

FizzBuzz

Print numbers 1 to 100. For multiples of 3 print Fizz, of 5 print Buzz, of both print FizzBuzz.

It sounds silly, but FizzBuzz is still asked in interviews, mostly as a filter. The interviewer isn't checking whether you know the trick. They want to see whether you can turn a plain-English rule into code without getting the order of the checks wrong.

What the output should start like:

1
2
Fizz
4
Buzz
Fizz
7
...
14
FizzBuzz

Before you write anything, think about 15. It's a multiple of 3 and 5. If your code checks "divisible by 3" first and stops there, 15 prints Fizz and you've failed the one case that matters.

Starter code

for i in range(1, 101):
    pass
💡 Hint 1

Use the modulo operator %

💡 Hint 2

Check the 'both' case first

✅ Show solution
for i in range(1, 101):
    out = ('Fizz' if i % 3 == 0 else '') + ('Buzz' if i % 5 == 0 else '')
    print(out or i)

How it works

Instead of four separate if branches, this builds the word up. If i divides by 3, add "Fizz". If it divides by 5, add "Buzz". For 15 you get both, so "FizzBuzz" comes out without a special case. If nothing was added, the string is empty, and out or i prints the number instead.

The more common version you'll see is this one, and it's completely fine in an interview:

for i in range(1, 101):
    if i % 15 == 0:
        print("FizzBuzz")
    elif i % 3 == 0:
        print("Fizz")
    elif i % 5 == 0:
        print("Buzz")
    else:
        print(i)

The only rule is that the 15 check has to come first.

Common mistakes

  • Using range(1, 100), which stops at 99.
  • Writing i % 3 == 0 and i % 5 == 0 after the separate checks, so it never runs.
  • Using / instead of %. Division gives you a float, not a remainder.

If the interviewer then says "now add Bazz for multiples of 7", the string-building version wins. You add one line rather than rewriting the whole chain.

Tip: run your code in a local Python environment, Jupyter or Google Colab.