Control Flow
if/elif/else, for loops, while loops, and when to use each.
What you will learn
- Branch with if/elif/else
- Iterate with for and range()
- Use while with a clear exit
Conditionals
python
score = 87
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
else:
grade = "C"
print(grade)Loops
python
for i in range(3):
print("tick", i)
count = 3
while count > 0:
print(count)
count -= 1Try it yourself
Print even numbers from 2 to 20 using a for loop.
