Python 201

A deeper look at Python for intermediate or advanced coders in upper middle or high school with a focus on real-world computing problems. Request Quote

Course Summary
  • Grades 8+
  • Advanced level
  • 15 lessons
  • Python
    • Web
Course Includes
  • 15 lessons
  • 129 activities
  • Enhanced Creativity Tools
  • Automatic Assessment
  • Tutorials and Reviews
  • Coding Puzzles
  • DIY Projects
  • Quizzes
  • Answer Keys
Prerequisites
No previous coding experience required.

Lesson Plan

Lesson: Lists

Time: 40+ mins

Introduction

In this lesson, students will use list data type to store a sequence of values using Python.

Vocabulary

  • List: A list is a data structure that stores a sequence of values enclosed in square brackets and separated by commas. The values stored in lists are called elements and like strings, elements can be accessed by index. For example,
    numbers = [5, 3, 12, 4, 9, 12]
  • Elements: A value that is stored in a list.
  • Mutable: Mutable objects are objects that can be modified after they are created. In Python, lists are mutable and programmers can change the individual values stored in lists without creating a new list.

Objectives

Students will...
  • Create lists in Python
  • Search and alter elements of lists
  • Use indexes to find particular elements or to create new lists
  • Perform operations on every element in a list using loops
  • Create programs to calculate statistics
  • Sort lists alphabetically
  • Add, remove, and count values in a list
  • Use lists as arguments in different functions

Materials

  • Computers (1 per student) with student account access to Tynker.com

Warm-Up (5 minutes)

  • Have students reflect on their experiences by creating a new KWL chart. This time, have them fill out the chart individually.
  • Remind students that the K-W-L chart tracks what they know (K), want to know (W), and have learned (L) in the Python 201 course. Here’s a template of the chart:

Activities (35 minutes)

Facilitate as students complete the Lists modules on their own:
1. Lists (Tutorial)
    • Students will read a short document that explains lists.
    • Are students struggling with the “Favorite list” puzzle? Give a hint: Tell them to use the code in the first example as a reference.
    • Are students struggling with the “List length” puzzle? Give a hint: Tell them to use a “while” loop.
    • Are students struggling with the “Snacktime” puzzle? Give a hint: Tell them to use the code in the “concatenating lists” example as a reference.
    • Tell students to click the “Next” button (located at the bottom of the document) to move on to the next module.
2. Searching a List (Tutorial)
    • In this module, students will read a short document that explains searching a list.
    • Optional: Before students select the “play” button in the first two examples, ask them to write down whether they think the code will output True or False.
    • Are students struggling with the “One digit prime” puzzle? Give a hint: Tell them to use the “in” operator to check if any of the one digit primes are in the list. Also, remind students that 1 is neither prime nor composite.
3. List Indexes (Tutorial)
    • Students will read a short document that explains list indexes.
    • Optional: Ask students to fix the error in the first section. Here’s one possible solution:
      presidents = ["George Washington", "John Adams", "Thomas Jefferson", "James Madison"]
      print( presidents[2] )
    • Are students struggling with the “Print introduction” puzzle? Give a hint: Tell them to use an equal to (==) operator and use an “if” statement to print a different formatted string for each possible length of the list.
    • Are students struggling with the “Changing area codes” puzzle? Give a hint: Tell them to try including a an equal to (==) operator as part of their solution.
    • Tell students to click the “Next” button to move on to the next module.
4. Index Ranges (Tutorial)
    • Students will read a short document that explains index ranges.
    • This module does not include puzzles.
    • Optional: Encourage students to use the code in the provided examples as a reference as they create their own examples that include an index range.
5. Changing Elements (Tutorial)
    • Students will read a short document that explains changing elements.
    • Are students struggling with the “Set middle to 0” puzzle? Give a hint: Tell students to use the “len()” function to find the length of the list, and divide by two to get the middle index. Part of their solution might look something like this:
      middle = len(numbers) / 2
    • Before students complete the “Coordinate reflection” puzzle, explain to your class that they can put a “-” sign in front of the word “coordinate” (e.g., -coordinate[1]).
6. List Iteration (Tutorial)
    • Students will read a short document that explains list iteration.
    • Check that students are trying the “Try This” activity, which encourages students to add another house to the list.
    • Are students struggling with the “Square every number” puzzle? Give a hint: Tell students to use code from the “Using a ‘while’ loop with lists” example as a reference. Also remind students of the square operator: **
7. Statistics (Tutorial)
    • In this module, students will read a short document that explains statistics, which is a branch of mathematics that studies the analysis of data.
    • Are students struggling with the “Find min” puzzle? Give a hint: Tell students to use the code in the “find largest value” section as a reference.
    • The puzzles in this module requires more math than previous puzzles, so encourage struggling students to work with a neighbor.
8. Comparing Adjacent Elements (Tutorial)
    • Students will read a short document that explains comparing adjacent elements.
    • Are students struggling with the “Print increasing pairs” puzzle? Give a hint: Tell students to use the code in the first example as a reference. Also, encourage students to include an “if” statement as part of their solution.
9. Binary Search (Tutorial)
    • Students will read a short document that explains a binary search.
    • This module does not contain puzzles.
    • Optional: Encourage students to experiment with the code in the provided examples. How did their changes affect the output?
10. List Operations (Tutorial)
    • Students will read a short document that explains list operations.
    • Students will need to solve two puzzles in this module. If students are struggling, direct their attention to the provided hint or encourage them to brainstorm possible solutions with a neighbor.
    • Optional: Challenge the adventurous coder to find at least two different solutions for the “Apples and oranges” puzzle.
11. Adding to a List (Tutorial)
    • Students will read a short document that explains functions that add new elements to a list.
    • Are students struggling with the “Pad right” puzzle? Give a hint: Tell students to use a “while” loop. Help them get started by providing the first line of code:
      while len(numbers) < 10:
    • Are students struggling with the “Pad left” puzzle? Give a hint: Tell students to include an “insert()” function as part of their solution.
12. Removing from a List (Tutorial)
    • Students will read a short document that explains functions that remove elements from a list.
    • Are students struggling with the “Remove all 0’s” puzzle? Give a hint: Tell students to include a “while” loop.
    • Are students struggling with the other puzzles? Direct their attention to the provided hints.
13. Ordering a List (Tutorial)
    • Students will read a short document that explains functions that can change the order of a list’s elements.
    • Emphasize to students that list functions modify the original list and do not create a copy.
    • This module contains one puzzle, but the solution is more complex than the provided examples. If students are struggling, direct their attention to the provided hint or encourage them to brainstorm possible solutions with a neighbor.
14. Functions with List Arguments (Tutorial)
    • Students will read a short document that explains certain built-in functions in Python that takes lists as arguments.
    • Optional: Ask students, “What does the ‘sum()’ function do?” (Returns the sum of the elements in a list)
    • Optional: Ask students, “Is ‘list.sort()’ the same as ‘sorted(list)’?” (No, calling “list.sort()” modifies the original list, while “sorted(list)” returns a new list.)
    • Are students struggling with the “First nonzero numbers” puzzle? Give a hint: Tell students to start an index at 0 and include a while loop.
    • Are students struggling with the “map max” puzzle? Give a hint: Tell students to use the code in “The map function” example as a reference.
15. Quiz
    • This quiz requires students to apply concepts from this lesson to solve 3 different puzzles. There are no multiple choice questions.

Discussion Questions/Follow-Up Activities (20 minutes)

Lead a discussion with your students:
    • What does it mean for something to be mutable? (A value can be modified after being created.)
    • Can lists be modified? If so, who can give an example? (Yes. For example, you can change the element at a certain index by assigning a new value to it.)
    • Can strings be modified? If so, who can give an example? (No)
    • How is “list.sort()” different from “sorted(list)?” (Calling “list.sort()” modifies the original list, while “sorted(list)” returns a new list.)

US Standards

  • CCSS-ELA: SL.8.1, RI.9-10.3, RI.9-10.6, RI.11-12.3, RI.11-12.6, L.9-10.3, L.9-10.6, L.11-12.3, L.11-12.6
  • CCSS-Math: HSN.Q.A.1, HSN.Q.A.2, HSN.Q.A.3, MP.1, MP.2, MP.4
  • CSTA: 2-AP-11, 2-AP-12, 2-AP-13, 2-AP-15, 2-AP-17, 3A-AP-14, 3A-AP-17, 3B-AP-11, 3B-AP-12
  • CS CA: 6-8.AP.11, 6-8.AP.12, 6-8.AP.13, 6-8.AP.15, 6-8.AP.17, 9-12.AP.12, 9-12.AP.14, 9-12.AP.16
  • ISTE: 1.c, 1.d, 4.d, 5.c, 5.d