Lesson 4.02: For Loops Using Range
Learning Objectives
Students will be able to…
- Define and identify: range
- Use the
rangeandlenfunction to to update lists via for loops
Materials/Preparation
- Do Now
-
Lab - Getting Loopy (printable lab document) (editable lab document)
- Associated Reading - section 4.2 of Book
- Read through the Do Now, lesson, and lab so that you are familiar with the requirements and can assist students
Pacing Guide
| Duration | Description |
|---|---|
| 5 Minutes | Do Now |
| 10 Minutes | Lesson |
| 35 Minutes | Lab |
| 5 Minutes | Debrief |
Instructor’s Notes
1. Do Now
- Display the Do Now on the board.
- Students experiment with and are introduced to the
rangefunction.
2. Lesson
Part 1 of the Do Now
- Ask students what the range function did.
- Remind them that there are reference docs online.
- Show the docs for the range function (note that it actually takes in a third value that is optional).
- Work together with the students to write a for loop just using the range function.
Part 2 of the Do Now
- Ask the students what happened
- Ask the students why these values might be helpful
- They are a list of the indices!
Part 3 (many students likely didn’t finish)
- Ask students to write the first line of the loop on the board
- Work together as a class to come to a solution that is demonstrated for all to see.
3. Lab
- Students re-write the fruit pluralizer program from yesterday’s do now, but without creating a new list.
- Students write a function that reverses the letters in a string.
4. Debrief
- Talk about any issues the students had with the lab today.
- Discuss how lists are mutable, so you don’t have to return a new value. Instead, the list is just updated as the loop runs.
Video explanation on Python Lists being Mutable
Accommodation/Differentiation
- If students are having a hard time with the fruit pluralizer, consider altering the fruit program to not allow fruit that ends in y.
- Some students may have issues with grabbing the last item of a string, consider providing tips or scaffolding for students that are struggling with this.
- Go over the bonus question if any students got to it. Discuss having a function inside of the loop and how that operated.
Forum discussion
Lesson 4.02: For Loops Using Range (TEALS Discourse Account Required)
