Lesson 2 · Data analytics zero to hero
Python Control Flow: If, For & While Loops | Data Analytics #2
Video two of the 30-part series: making decisions and repeating work with if/else and loops. If you haven't seen video one on variables and data types,…
- CourseData analytics zero to hero
- Lesson2 of 30
- Video11 min
- FormatJupyter notebook · 12 code cells
What you'll learn
Data
No separate download needed — the notebook creates or downloads everything it uses.
📓 Full notebook
Download .ipynbData Analytics Zero to Hero, Video 2: Control Flow#
- Video two of the 30-part series: making decisions and repeating work with if/else and loops.
- If you haven't seen video one on variables and data types, that's the natural starting point.
- Let's jump straight in.
Before You Start#
- Open a new Jupyter Notebook in VS Code and select your Python interpreter as the kernel.
Part 1: if, elif, and else#
score = 82
if score >= 70:
print('Pass')
score = 55
if score >= 70:
print('Pass')
else:
print('Fail')
score = 75
if score >= 90:
grade = 'A'
elif score >= 80:
grade = 'B'
elif score >= 70:
grade = 'C'
else:
grade = 'D'
print(grade)
Part 2: for Loops#
prices = [19.99, 45.50, 12.75, 88.00]
for price in prices:
print(price)
for i in range(5):
print(i)
total = 0
prices = [19.99, 45.50, 12.75, 88.00]
for price in prices:
total = total + price
print(f'Total: ${total:.2f}')
prices = [19.99, 45.50, 12.75, 88.00]
for index, price in enumerate(prices):
print(f'Item {index}: ${price}')
Part 3: while Loops#
count = 0
while count < 5:
print(count)
count = count + 1
break and continue#
for number in range(10):
if number == 5:
break
print(number)
for number in range(10):
if number % 2 != 0:
continue
print(number)
Part 4: List Comprehensions#
prices = [19.99, 45.50, 12.75, 88.00]
discounted = [price * 0.9 for price in prices]
print(discounted)
prices = [19.99, 45.50, 12.75, 88.00]
expensive = [price for price in prices if price > 20]
print(expensive)
Wrap-Up: What You Learned#
- if, elif, and else for branching logic based on conditions.
- for loops for iterating over a sequence, plus enumerate for tracking position.
- while loops for repeating until a condition changes, and why you must update that condition yourself.
- break to exit a loop early, and continue to skip to the next pass.
- List comprehensions for building and filtering lists in a single compact line.
- Control flow is how your code makes decisions and does repeated work; video three covers functions and modules, so you can package this logic up and reuse it. Subscribe so it lands automatically see you there.
Found this useful?
All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.



