Day 19 - 2D Lists and Nested Loops

Day 19: 2D Lists and Nested Loops

Learning Objectives

Essential Questions

Materials Needed

Vocabulary

Procedure (50 minutes)

Opening (8 minutes)

  1. Review and Connection (3 minutes)

    • Review list traversal from previous lesson
    • Connect to today's focus on representing and processing 2D data
  2. Warm-up Activity (5 minutes)

    • Present a real-world scenario involving 2D data (e.g., seating chart, game board)
    • Ask students how they might represent this data using lists
    • Introduce the concept of lists containing other lists

Main Activities (32 minutes)

  1. Lecture: 2D Lists/Arrays and Nested Data Structures (12 minutes)

    • Define 2D lists as lists containing other lists
    • Explain how 2D lists represent tabular or grid-based data:
      • Rows and columns
      • Coordinates (row, column)
      • Real-world examples (game boards, spreadsheets, images)
    • Demonstrate creating 2D lists:
      • grid ← [[value1, value2], [value3, value4], ...]
      • Visualizing the structure as a grid
    • Explain accessing elements in 2D lists:
      • Using two indices: grid[row][column]
      • Understanding row-major order
    • Discuss modifying elements in 2D lists
    • Introduce nested loops for processing 2D lists:
      • Outer loop for rows
      • Inner loop for columns
      • How nested loops traverse the entire structure
    • Explain common operations on 2D lists:
      • Initializing a grid
      • Accessing all elements
      • Finding values
      • Calculating row/column sums
      • Transforming the grid
  2. Demo: Creating and Accessing 2D List Elements (8 minutes)

    • Walk through examples of working with 2D lists:
      • Creating a 2D list representing a game board
      • Accessing specific elements by row and column
      • Modifying elements in the grid
      • Traversing the entire grid with nested loops
      • Processing rows or columns individually
    • Demonstrate common patterns for 2D list manipulation:
      • Initializing a grid of a specific size
      • Finding values in a grid
      • Calculating statistics for rows or columns
      • Transforming the entire grid
    • Show how to visualize 2D lists for better understanding
    • Highlight common errors and pitfalls
  3. Hands-on: Manipulating 2D Lists (12 minutes)

    • Students work in the programming environment
    • Guide students through creating and manipulating 2D lists
    • Have students implement programs that:
      • Create and initialize 2D lists
      • Access and modify elements by position
      • Traverse the grid using nested loops
      • Perform calculations on rows or columns
      • Implement simple grid-based algorithms
    • Encourage students to visualize their 2D lists as grids
    • Challenge students to solve problems requiring 2D data representation

Closing (10 minutes)

  1. Activity: Implementing a Grid-Based Application (5 minutes)

    • Students design and implement a simple grid-based application
    • Application ideas:
      • Simple game board (tic-tac-toe, minesweeper)
      • Seating chart manager
      • Image representation (using numbers for colors)
      • Simple spreadsheet
    • Share and discuss different implementations
    • Highlight effective use of 2D lists and nested loops
  2. Exit Ticket and Preview (5 minutes)

    • Students develop a program that effectively uses 2D lists
    • Preview that next class will focus on other collection types

Assessment

Differentiation

For Advanced Students

For Struggling Students

Homework/Extension

Teacher Notes