Week 5: Control Flow, Loops & Functions

2025-06-20

Welcome to Week 5!

Theme: Control Flow, Loops & Functions

This week we cover:

  • Conditionals (if/else)

  • Loop constructs (for, while)

  • Functions & code reuse

Why this matters: Enable logic, iteration, and modularity in your Python programs.

Control Flow: if, elif, else

x = 10
if x < 0:
    print("Negative")
elif x == 0:
    print("Zero")
else:
    print("Positive")


- if checks a condition
- elif for additional checks
- else is the default fallback

Real world Example

score = 75
if score >= 90:
    grade = "A"
elif score >= 80:
    grade = "B"
elif score >= 70:
    grade = "C"
else:
    grade = "D/F"
print(f"You got: {grade}")

Loops: for and while

for loop – iterate over a sequence

for item in ["apple", "banana", "cherry"]:
    print(item)


while loop – repeat until condition is false

count = 0
while count < 3:
    print(count)
    count += 1

Functions: Definitions & Usage

def greet(name):
    return f"Hello, {name}!"

print(greet("Alice"))


  • def keyword defines a function
  • Functions can return values
  • Reusable and modular

Let’s Dive Into The Live Session