Mini Project: FizzBuzz
Lesson 7 of 7 · View course roadmap
Learn the idea
Time to combine everything — variables, math, conditionals and loops — into the most famous beginner program (and a real interview question!): FizzBuzz.
The rules, for each number from 1 to n:
- Divisible by 3 and 5 → print
FizzBuzz - Divisible by only 3 → print
Fizz - Divisible by only 5 → print
Buzz - Otherwise → print the number itself
Key insight: check the "divisible by both" case first — if you check 3 alone first, 15 would print Fizz and never reach the FizzBuzz branch. Order of conditions matters.
Where you'll use this
FizzBuzz is a genuine screening question at real companies — interviewers use it because a surprising share of applicants can't order the conditions correctly. You now can, on demand.
Common mistakes
- Checking
% 3before% 15— the most specific condition must come first in any if/elif chain. - Printing
"15"-style strings instead of the number for the default case —print(i), notprint("i").
Pro tip
A slicker variant builds the word: word = "Fizz" * (i % 3 == 0) + "Buzz" * (i % 5 == 0); print(word or i). Understand why that works (bool × str, empty string is falsy) and you've leveled up.
Watch how it runs — line by line
Press play to watch Python execute this code, one line at a time.
Try it yourself
The lesson example is loaded and ready — press Run, then change something and run it again. Breaking it is part of learning. Want a clean slate? Tap “New blank”.
Output appears here…
Pass the challenge +40 XP
Write FizzBuzz for the numbers 1 to 15, printing one result per line.
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
Test i % 15 == 0 first (or i % 3 == 0 and i % 5 == 0), then % 3, then % 5, else print(i). Remove the pass line.
for i in range(1, 16):
if i % 15 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)
Run your code to check it…
Check your understanding
Your notes (saved on this device)
Tip: use ← and → to move between lessons, ⌘K to search everything.