Lesson 4.02: For Loops Using Range
Learning Objectives
Students will be able to...
- Define and identify: range
- Use the
range
andlen
function to to update lists via for loops
Materials/Preparation
- Do Now
- Lab - Getting Loopy
- 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
- Do Now
- Display the Do Now on the board.
- Students experiment with and are introduced to the
range
function.
- Lesson
- Go over 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.
- Go over 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!
- Go Over 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.
- 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.
- 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.
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.