What’s one thing you learned? What’s still confusing?
Functions: Reuse, Scope & First-Class Citizens
Define functions, master LEGB scope, *args/**kwargs, default arguments, lambdas, and closures.
Mini-Project: Tip Calculator
Build a tip + tax + split calculator with default parameters and tuple returns — your first reusable mini-library.
Lists, Tuples & Sets
Python's core sequences — lists, tuples, sets, frozensets — with time complexity of every operation.
Interactive Labs for This Track
Loop Visualizer
You're a factory robot repeating the same task on an assembly line — watch how loops automate repetitive work
List Slicing
You have a playlist of 50 songs — grab just tracks 10 through 20 with a single slice expression
Sorting Algorithms
You're organizing a library of 10,000 books — which sorting method is fastest?
Ask questions, share insights
A program that prints the numbers 1 to 100, but with a twist:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
...
for ... in range(...)% reveals divisibilityif/elif/else branches so the most specific case winsfor loop and range(). Remember that range(1, 16) produces 1, 2, 3, ... 15 -- the upper bound is excluded.for n in range(1, 16):
print(n)range(1, 16) and not range(1, 15) -- the second argument is exclusive. Off-by-one errors here are the most common beginner mistake in Python.What does 10 % 3 evaluate to?
% operator (modulo) returns the REMAINDER after division, not the quotient. 10 ÷ 3 = 3 with 1 left over — that 1 is what modulo returns. This is the foundation of FizzBuzz: n % 3 == 0 is True only when there's no remainder, meaning n is exactly divisible by 3. Modulo is also how you check if a number is even (n % 2 == 0) or get the last digit of a number (n % 10).How many numbers does `range(1, 16)` produce?
%) returns the remainder after division. If n % 15 == 0, then 15 divides n evenly -- meaning n is a multiple of 15.for n in range(1, 31):
if n % 15 == 0:
print("FizzBuzz")
else:
print(n)15 and 30 should print FizzBuzz; everything else prints the number. Verify before moving on.
What does this print for n = 15? if n % 3 == 0: print("Fizz") elif n % 5 == 0: print("Buzz") else: print(n)
elif is short-circuit: as soon as n % 3 == 0 matches, Python runs that branch and skips the rest. The % 5 check never even happens. This is exactly why FizzBuzz needs the % 15 check FIRST — without it, every multiple of 15 silently becomes "Fizz" instead of "FizzBuzz". One missing branch ruins the whole program in a way no error catches.Now extend with two more branches -- multiples of 3 print "Fizz", multiples of 5 print "Buzz". Order matters here.
for n in range(1, 16):
if n % 15 == 0:
print("FizzBuzz")
elif n % 3 == 0:
print("Fizz")
elif n % 5 == 0:
print("Buzz")
else:
print(n)n % 3 first, then 15 would print "Fizz" because 15 is also a multiple of 3 -- and the elif short-circuits before the "FizzBuzz" branch ever runs.What happens if you check `n % 3 == 0` before `n % 15 == 0`?
range().for n in range(1, 101):
if n % 15 == 0:
print("FizzBuzz")
elif n % 3 == 0:
print("Fizz")
elif n % 5 == 0:
print("Buzz")
else:
print(n)That's it -- the entire FizzBuzz problem in 9 lines. The output is 100 lines long, with "FizzBuzz" at 15, 30, 45, 60, 75, 90.
What does this print for n = 30? print(n % 3 == 0 and n % 5 == 0)
30 % 3 is 0 (30 divides evenly by 3), and 30 % 5 is also 0. Both comparisons 0 == 0 are True, and True and True is True. This expression is the LOGICAL equivalent of n % 15 == 0 — both detect multiples of 15. The and version is sometimes clearer because it explicitly shows both rules; the % 15 version is faster because it's one operation. Both are correct.Print each number from 1 to 100 on its own line. Replace multiples of 3 with 'Fizz', multiples of 5 with 'Buzz', and multiples of both (i.e., 15) with 'FizzBuzz'. Use only one loop and a single if/elif/else chain.
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
... (continues to 100)# FizzBuzz 1 to 100
for n in range(1, 101):
# TODO: if n is a multiple of 15 -> print 'FizzBuzz'
# TODO: elif n is a multiple of 3 -> print 'Fizz'
# TODO: elif n is a multiple of 5 -> print 'Buzz'
# TODO: else -> print n
pass
Try one of these variations:
% 15 check.)print(", ".join(results)).