Lists, Loops, and Traversals - Lesson 3: Lists Practice

Overview

Practice the basics of lists including creating lists and accessing, inserting, and removing elements from lists.

Goals

Students will be able to:

  • Correctly set up a list in a program
  • Debug programs with lists
  • Accurately use list operations including accessing, inserting, and removing elements

Purpose

This lesson is students primary opportunity to get hands on with lists in code prior to the Make activity in the following lesson. Give students as much class time as you can to work through these. For this lesson it's recommended that you place students in pairs as a support and to encourage discussion about the challenges or concepts they're seeing.

Resources

For the students

Getting Started (5 minutes)

Do This: Run a quick vocabulary review with students.

  • List - an ordered collection of elements
  • Element - an individual value in a list that is assigned a unique index
  • Index - a common method for referencing the elements in a list or string using numbers

Remarks

  • Today we're going to have a chance to practice programming with a lot of the concepts and patterns we've explored over the last two lessons. I encourage you to go through these with a partner, but pay close attention to what each other is doing. In our next lesson you're going to have to use a lot of these on an independent project, and these activities are good practice for what you'll find there! Alright, let's get to it!

Activity (35 minutes)

Practice Time

Teaching Tip

Providing Support: Circulate around the room through the lesson encouraging students to use the strategies introduced at the beginning of the lesson. Students have a number of supports at their fingertips, so a big part of your role is helping build their independence in using those resources.

Common Errors: The following are common errors students may encounter in this lesson:

  • The last index in an array is at array:GetSize() - 1 because the first index is 0. One of the most common errors with arrays, therefore, is trying to access indexes that are out of bounds, most notably array:GetSize().
  • Syntax errors are common with arrays because the syntax is new. In particular, students might be confused how the Add command can accept different inputs to add to the end or the middle of a list.
  • When using the patterns students may become overly reliant on simply copying and pasting without thinking through what the code from the patterns does. They may reference variables that don't exist in their program, for example, because it is in the example code of the pattern.

Display: Remind students of the debugging process, including some of these important skills:

  • Try to zoom in on precisely where you're getting stuck.
  • Talk to your partner! That's what they're there for!
  • Talk to the group next to you. If another group asks for help make sure to take some time to talk it through with them.

Display: Highlight important debugging skills specifically for lists including ways to use the Watch panel and the Debug Console with lists.

Display: Quickly introduce the fact that strings have indexes too. Students will see text:GetSize() and text:GetSubtext(start, end) during the lesson so this is just calling out a concept that students will need to recognize when they get to it. You may optionally use slide 46 from CSP Unit 5 Presentation Slides to present this information. While the slide uses Javascript instead of Quorum, the concept is the same in both languages.

Open a Project: Students will be using a number of projects to practice today. Direct students to begin with Lesson3_App1 of Unit 5 in the CSP-Widgets repository.

Apps 1-2 Setting Up Lists: These levels involve setting up a list and printing the list to the console.

  • Level 1 App 1: A list of numbers
  • Level 2 App 2: A list of strings

Apps 3-5 Accessing Elements in a List: Students practice accessing elements in a list using the index. These levels also practice the random list access and list scrolling pattern students saw in the Investigate lesson.

  • Level 3 App 3: Students practice printing specific elements to the console using the Get(index) command.
  • Level 4 App 4: Students build a "Magic 8 Ball" app that uses the Random List Access pattern.
  • Level 5 App 5: Students build a "Class Schedule" app that uses the List Scrolling pattern.
Teaching Tip
  • App 5: Ask students to add the ability to add new classes to the list in the Class Schedule app.
  • App 10: Ask students to add the ability to remove items in the Food Diary app.
  • App 11: Ask students to add a button that will "Undo" adding the most recent song to the list. This is pretty tricky and requires keeping track of some new information.

Extension activities

App 6-7 Strings and Indexes: Students practice accessing characters in a string.

  • Level 6 App 6: Students practice printing the length and first characters of strings.
  • Level 7 App 7: Students debug code that uses text:GetSubtext(start, end) to grab different parts of a date stored as a string.

Apps 8-11 List Operations: In these levels, students work with list operations: Add(element), RemoveAt(index), and Add(index, element).

  • Level 8 App 8: Students practice using Add(element) to increase the size of a list.
  • Level 9 App 9: Students modify a "Food Diary" app so that the user can add new elements to a list.
  • Level 10 App 10: Students practice using RemoveAt(index) and Add(index, element) to modify lists.
  • Level 11 App 11: Students modify a "Top Ten Songs" app so that the user can add new items into the middle of a list while keeping the total length of the list to 10.

Wrap up (5 Minutes)

Discussion

Prompt: What aspects of working with lists do you feel like clicked today? What do you still feel like you have trouble with?

Discuss: Have students share with one another before sharing with the whole class.

Goal: Use this opportunity to address any lingering questions or misconceptions in the room. You can also use this as a source of discussion topics to kick off the following lesson. As you lead the discussion, call out the many resources students have access to help when they're getting stuck.

Remarks

  • Working with lists can be tricky - especially working with the index. We will get more practice tomorrow by making an app that uses lists to store information.
gems <- ["ruby", "sapphire", "garnet"]
gems <- ["opal", "emerald"]
DISPLAY(gems[1])
luckyNumbers <- [15, 33, 25]
INSERT(luckyNumbers, 2, 13)
APPEND(luckyNumbers, 3)
REMOVE(luckyNumbers, 1)
DISPLAY(LENGTH(luckyNumbers))

Assessment: Check for Understanding - AP Practice

Check For Understanding Question(s) and solutions can be found in each lesson on Code Studio. These questions can be used for an exit ticket.

For Students

Open a word doc or google doc and copy/paste the following question.

Question 1

What will be displayed after this code snippet is run?

Question 2

What will be displayed after this code snippet is run?

Standards Alignment

  • CSTA K-12 Computer Science Standards (2017): 3A-AP-14
  • CSP2021: AAP-1.D.7, AAP-1.D.8
  • CSP2021: AAP-2.D.2
  • CSP2021: AAP-2.N.1, AAP-2.N.2
  • CSP2021: AAP-2.0.3

Next Tutorial

In the next tutorial, we will discuss Code.Org Unit 5 Lesson 4, which describes Use lists to make an app.