Lecture

Control Flow & Data Structures Recap

In Python, logic and data work together. You need both to write useful programs.

This lesson brings together what you've learned about control flow (if, for, and while) and data structures (lists, sets, and dictionaries).

We will not focus on detailed syntax here. Instead, we will look at how to think with these tools.


What's the Big Idea?

Python lets you describe what to do (loop, choose, repeat) and what to do it with (lists, sets, dictionaries).

This makes your programs flexible:

  • Choose the data structure that best fits the task.
  • Use control flow to work with that data in meaningful ways.

Example: Want to find which students passed?

  • Use a dict to store names and scores.
  • Use a for loop to go through each one.
  • Use an if statement to check if the score is high enough.

Code Example

Here's how it looks in code:

Control Flow and Data Structures
grades = {"Alina": 88, "Mike": 76, "John": 91} for name, score in grades.items(): if score >= 85: print(name, "did well!") else: print(name, "needs improvement.")

For each item in the grades dictionary, the for loop checks if the value is greater than or equal to 85.

If it is, the program prints a message saying that the student did well.

Otherwise, it prints a message saying that the student needs improvement.

Quiz
0 / 1

Which data structure is best for storing student names and scores?

A is best for storing student names and scores.
list
dictionary
set
tuple

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help