AP CSP CodeX - Traversing a List Lesson 1

Traversing a List Lesson 1 Lesson Plan

Traversing a List Lesson 1

Students traverse a list with a for loop in three programs, including traversing a list more than once.

⏰ 45 min 🎯 Grades 9-12 💻 CodeSpace 🎮 CodeX 🐍 Python
View Lesson Outline
📋

Overview

Students work on computers in the CodeSpace Sandbox. This lesson is not part of a mission. Students add functions to Answer_Bot and Billboard and modify Game_Spinner so each program traverses a list. They compare a for loop with a specialized for loop, use modulo division to traverse a list more than once, and complete the Wrap-Up questions on the Activity Guide.

🎯 Mission Goal: Students will traverse a single list using a for loop in a program.

🎯

Learning Targets

  • I can traverse a list using a for loop.
  • I can traverse a list using a specialized for loop.
  • I can traverse a list multiple times without getting an index out of range error.
💡

Key Concepts

  • Traversing a list means accessing each element in a list, in order.
  • The easiest way to traverse a list is to use a for loop.
  • Use a specialized for loop to traverse a list one time.
  • You can traverse a list multiple times using a for loop.
✅

Assessment Opportunities

☑️

Success Criteria

  • Traverse a list using a for loop
  • Traverse a list using a specialized for loop
  • Traverse a list multiple times using a for loop and the modulo operator
📁

Digital Resources

🧰

Classroom Materials

  • ▸CodeX
  • ▸USB-C cable
  • ▸Computer
🚀

Extensions & Cross-Curricular

ExtensionStudents add a function to Answer_Bot_traversal that traverses the list to check whether a word typed by the user is one of the answers, and display the result.
ExtensionStudents add a second list to Billboard_traversal and use a for loop with an index to traverse both lists at the same time, like the two-list loop in the New Python Code section.
MathStudents work out by hand what 29 % 8 equals and what that means for a list with 8 items, then change the number of steps in Game_Spinner_traversal and predict the index each time.
Lang ArtsStudents write a short explanation of the difference between a for loop and a specialized for loop, and when each one works best, for a classmate who missed the lesson.
🔤

Vocabulary

▾
Traverse - Traveling or traversing through a list one element at a time, in order, starting with index 0 (first element) and going through to the last element (index len-1).
Data abstraction - The technique that simplifies complex data, making data easier to manage and use.
Matrix - A list of lists, or a 2D list. Each element in the list is a list itself.
Sequence - Executing code line by line, one after another, in order.
Selection - Decision points in code; a condition (this isn't in the documentation but is used in AP CSP).
Iteration - The repeating portion of an algorithm; code that repeats until a given condition is met or a specified number of times.
🐍

New Python Code

▾
for index in range(len(answers)): display.print(answers[index]) sleep(1)For loop that traverses a list.
for item in answers: display.print(item) sleep(1)Specialized for loop. (traverses a list)
for pix in range(4): pixls.set(pix, random.choice(COLOR_LIST))For loop that turns on pixels.
for index in range(len(pix_colors)): turn_pixels(pix_colors[index], pix_brights[index])For loop that traverses two lists at the same time.
📐

Standards

▾

CSTA Standards - Grades 9-10

3A-CS-03 3A-AP-13 3A-AP-14 3A-AP-15 3A-AP-16 3A-AP-17 3A-AP-18

CSTA Standards - Grades 11-12

3B-AP-10 3B-AP-11 3B-AP-14 3B-AP-15 3B-AP-17 3B-AP-22 3B-AP-23

AP CSP Framework

AAP-1.D - Develop data abstraction using lists to store multiple elements.
AAP-2.N - Write expressions that use list indexing and list procedures.
AAP-2.O - Write iteration statements to traverse a list.
Computational Thinking Practice 3.B - Use abstraction to manage complexity in a program.
Computational Thinking Practice 4.C - Identify and correct errors in algorithms and programs, including error discovery through testing.
📝
Preparing for the Lesson
  • Make sure students can open their Answer_Bot_parameters, Billboard_functions, and Game_Spinner programs in the CodeSpace Sandbox. Students who need the original code can use the most recent version of each program from the class dashboard.
  • Prepare the Activity Guide to give to students. It is used for notes during the lesson and for the Wrap-Up questions at the end.
  • If you have a word wall, or another form of vocabulary presentation, prepare the terms.

🧑‍🏫
Teacher Notes
  • Students complete this lesson on the computer, using the Sandbox in CodeSpace for programming. This lesson is not part of a mission.
  • Students add functions to Answer_Bot and Billboard, and also modify the Game_Spinner program.
  • The best experience will come from students modifying their own code. However, we want all students to be engaged, so you can give them the original code to modify if needed.
  • The most recent version of each program can be found in the class dashboard. If you are giving code to students, use the solution code from these lessons:
  • Answer_Bot_parameters: Unit 3 Functions with Parameters Lesson 2
  • Billboard_functions: Unit 2 Mission 7
  • Game_Spinner: Unit 3 Mission 9 (with or without modulo)
  • Solution code for all finished programs is provided.
  • Follow the slides for instructions and guidance.
🗺️

Lesson Outline

This outline gives one way to present the lesson.

🗣️Warm-up

Review lists with students.

  • Slide 2: Students write down at least three things about lists in their Activity Guide. You can have them do a think-pair-share, etc.
📖Traversing a List

💻 Students do not need a computer for this part. They can take notes or have a discussion as needed.

Teaching tip: Go through slides 3-5.
💻Example #1 - Answer_Bot

💻 Students use the Answer_Bot_parameters program from Unit 3 Functions with Parameters Lesson 2.

Teaching tip: Go through slides 6-16. They give step-by-step instructions for modifying the program by traversing a list. They also show a comparison of different loops used to traverse a list.
💻Example #2 - Billboard

💻 Students use the Billboard_functions program from Unit 2 Mission 7 (not the one with parameters).

Teaching tip: Go through slides 17-19. They give instructions for traversing the list.
💻Example #3 - Game_Spinner

💻 Students use the Game_Spinner program from Unit 3 Mission 9. Students can use the original version or the one with modulo.

Teaching tip: Go through slides 20-26. They give instructions for traversing the list. If students are using a version of the program that has modulo for the index, then they will already have the code for slides 25-26.
📝Review

💻 Students do not use the computer for this activity.

Teaching tip: Complete the Wrap-Up questions on the Activity Guide.

✅ The Activity Guide and three programs are complete and ready to turn in.

🧑‍🤝‍🧑Wrap-Up

✅ Formative assessment:

  • "Wrap-Up" questions at the end of the Activity Guide
  • Daily reflection journal or Google Form
  • Class discussion on what they learned about lists
  • Exit ticket