×

python · level 1 · unit 7 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Big programs are small pieces working as a team.

Real programs are built from small parts. A list holds the data. A loop walks through it. A function answers one small question, and an if decides what to do with each answer.

Here, return rating >= 7 hands back True or False, so the answer slots straight into an if. Each piece is tiny, but together they spot every rating worth a yum.

When something goes wrong, you : find the bug, fix it, run again. Every programmer does this every day. Small functions help, because you can test each one on its own.

def is_tasty(rating):
    return rating >= 7
ratings = [9, 3, 8, 5]
for rating in ratings:
    if is_tasty(rating):
        print(f"{rating} out of 10. Yum!")

Test each function on its own first, then put the pieces together.