Overview
Print 1..n; replace multiples of 3 with Fizz, multiples of 5 with Buzz, both with FizzBuzz.
Analogy
A children's counting game with special words replacing certain numbers.
Step-by-step
- Loop i from 1 to n.
- if i%15==0: FizzBuzz (check combined first!).
- elif i%3==0: Fizz.
- elif i%5==0: Buzz.
- else: print i.
Visual
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
Common mistakes
- Checking 3 and 5 before 15 (15 would be caught by 3 and print just 'Fizz').
- Using i%3==0 and i%5==0 in elif chain instead of checking 15 first.
Practice questions
- Generalize to FizzBuzzJazz for multiples of 7.
- Build a version that takes a list of (divisor, word) pairs.