Title Slide
• Understanding Programming Constructs in
Python
• Using Loops and Decisions Made Simple
• Instructor: [Your Name]
Lesson Objectives
• - Understand iteration and selection
• - Use `for` and `while` loops
• - Use `if`, `elif`, `else`
• - Write simple Python programs
What is Iteration?
• - Doing something again and again
• - Python uses loops:
• - `for` (known times)
• - `while` (until a condition)
The `for` Loop
• data = [5, 2, 8, 1, 9]
• for num in data:
• print(num)
Using `range()` with `for`
• for i in range(3):
• print("Keep learning Python!")
The `while` Loop
• index = 0
• while index < len(data):
• print(data[index])
• index += 1
Searching with `while`
• target = 8
• index = 0
• found = False
• while index < len(data):
• if data[index] == target:
• found = True
• break
• index += 1
• print("Found:", found)
What is Selection?
• - Choosing based on a condition
• - Use `if`, `elif`, `else`
Simple Selection Example
• age = 14
• if age >= 18:
• print("You can vote.")
• elif age >= 13:
• print("You are a teenager.")
• else:
• print("You are a child.")
Using Selection with Loops
• scores = [70, 45, 90, 60, 30]
• for score in scores:
• if score >= 50:
• print("Pass")
• else:
• print("Fail")
Group Exercise
• - Loop through ages
• - Print "Adult", "Teen", or "Child" using `if`
Recap and Q&A
• - `for`: known repetitions
• - `while`: condition-based
• - `if/else`: decisions
Homework Assignment
• - Ask for 5 numbers
• - Print “Even” or “Odd” using loops and `if`
Thank You!
• Questions?
• Let’s try writing more programs together!