Lesson 2: Loops + Functions (Faster Pace)
Learning Intentions
- Move through loop and function fundamentals at Y9 pace.
- introduce list comprehensions and *args.
Success Criteria
- I can explain when to use for vs while.
- I've written a function with parameters and a return value.
- I've used a list comprehension for the first time.
๐ Do Now โ Error of the Day
Predict the output: print([x*2 for x in range(5)]) โ what prints? (Hint: that's a list comprehension โ new to you.)
๐ I Do โ Teacher Demo
Live-code: (1) quick for-loop refresh; (2) introduce list comprehension syntax; (3) define a function calculate_damage(hp, damage, armour) with return value; (4) show *args with total_score(*scores).
๐ค We Do โ Build Together
Class types along: build a function count_alive(characters) that loops a list and counts those with hp > 0. Introduce scope by showing what happens if you try to read a local variable from outside.
๐ You Do โ Your Turn
Work through the arcade quests below. Mix of predict-output, typing drills, and code tasks. Aim for 8-12 quests this session.
- List comprehension exercises (squares, evens, filter)
- Function challenge: write calculate_damage(hp, damage, armour)
- Write a function that returns multiple values using a tuple
๐ฎ Practice Quests โ work through these
Loading practice quests for this lesson...
Three tiers โ pick yours
Support
scaffolded functions with TODO in body
Core
standard
Extension
recursive challenges
Extensions
- Write a recursive factorial function.
- Use *args to accept any number of scores; return average.
๐ Exit Ticket โ Coding Journal
Journal: write one 3-line function you wrote today + one line explaining what it does.
Evidence of Learning
Student solutions show working loops + functions. Can explain scope (variables inside functions are local).