Control flow
Make decisions and repeat work with if, for and while.
What you will be able to do
- Write if/elif/else chains
- Loop over ranges and lists
- Use break and continue
Control flow is how a program makes decisions and repeats work. Conditions are truthy or falsy; comparisons produce booleans.
score = 78
if score >= 90:
level = "excellent"
elif score >= 75:
level = "passed"
else:
level = "retry"
for day in range(1, 6):
print(f"Study day {day}")
while score < 90:
score += 2- break exits the loop immediately.
- continue skips to the next iteration.
- range(1, 6) yields 1 through 5 — the end is exclusive.
Your turn
MediumFizzBuzz, briefly
Print numbers 1–15. For multiples of 3 print "Fizz", for 5 print "Buzz", for both print "FizzBuzz".
PYTHON · starter
for n in range(1, 16):
# your code here
passCheck your understanding before moving on.
Knowledge checkQuestion 1
What does range(3) produce?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.