Lesson Summary

Summary

This lesson answers the question "What is a list and what can I do with one?". Students will find the answer to this question by exploring list operations and methods, as well as investigating how lists are modeled in real-world situations.

Outcomes

  • Students will create lists, access, and traverse elements within the list.
  • Students will perform list operations including insertion, concatenation, repetition, slices, and deletion.
  • Students will be introduced to list methods including append, insert, pop, sort, reverse, index, count, and remove.
  • Students will explore the Python API.
  • Students will use lists to model several real-world situations.

Overview

Session 1

  1. Getting Started (5 min)
    1. Introduction [3 min]
    2. Discussion [2 min]
  2. Guided Activities (40 min)
    1. Listy Linkys RolePlay [20 min]
    2. Python Documentation [10 min]
    3. List Slices [10 min]
  3. Wrap Up (5 min)
    1. Homework

Session 2

  1. Getting Started (5 min)
  2. Guided Activities (40 min)
    1. Lists are Mutable [20 min]
    2. Paired Programming [20 min]
  3. Wrap Up (5 min)
    1. Homework

Learning Objectives

CSP Objectives

Big Idea - Creativity
  • EU 1.2 - Computing enables people to use creative development processes to create computational artifacts for creative expression or to solve a problem.
    • LO 1.2.4 - Collaborate in the creation of computational artifacts. [P6]
      • EK 1.2.4A - A collaboratively created computational artifact reflects effort by more than one person.
  • EU 1.3 - Computing can extend traditional forms of human expression and experience.
    • LO 1.3.1 - Use computing tools and techniques for creative expression. [P2]
      • EK 1.3.1E - Computing enables creative exploration of both real and virtual phenomena.
Big Idea - Algorithms
  • EU 4.1 - Algorithms are precise sequences of instructions for processes that can be executed by a computer and are implemented using programming languages.
    • LO 4.1.1 - Develop an algorithm for implementation in a program. [P2]
      • EK 4.1.1A - Sequencing, selection, and iteration are building blocks of algorithms.
      • EK 4.1.1B - Sequencing is the application of each step of an algorithm in the order in which the statements are given.
      • EK 4.1.1C - Selection uses a Boolean condition to determine which of two parts of an algorithm is used.
      • EK 4.1.1D - Iteration is the repetition of part of an algorithm until a condition is met or for a specified number of times.
      • EK 4.1.1E - Algorithms can be combined to make new algorithms.
      • EK 4.1.1H - Different algorithms can be developed to solve the same problem.
      • EK 4.1.1I - Developing a new algorithm to solve a problem can yield insight into the problem.
    • LO 4.1.2 - Express an algorithm in a language. [P5]
      • EK 4.1.2A - Languages for algorithms include natural language, pseudocode, and visual and textual programming languages.
      • EK 4.1.2B - Natural language and pseudocode describe algorithms so that humans can understand them.
      • EK 4.1.2C - Algorithms described in programming languages can be executed on a computer.
      • EK 4.1.2G - Every algorithm can be constructed using only sequencing, selection, and iteration.
Big Idea - Programming
  • EU 5.1 - Programs can be developed for creative expression, to satisfy personal curiosity, to create new knowledge, or to solve problems (to help people, organizations, or society).
    • LO 5.1.1 - Develop a program for creative expression, to satisfy personal curiosity, or to create new knowledge. [P2]
      • EK 5.1.1A - Programs are developed and used in a variety of ways by a wide range of people depending on the goals of the programmer.
      • EK 5.1.1B - Programs developed for creative expression, to satisfy personal curiosity, or to create new knowledge may have visual, audible, or tactile inputs and outputs.
      • EK 5.1.1C - Programs developed for creative expression, to satisfy personal curiosity, or to create new knowledge may be developed with different standards or methods than programs developed for widespread distribution.
      • EK 5.1.1D - Additional desired outcomes may be realized independently of the original purpose of the program.
    • LO 5.1.2 - Develop a correct program to solve problems. [P2]
      • EK 5.1.2A - An iterative process of program development helps in developing a correct program to solve problems.
      • EK 5.1.2B - Developing correct program components and then combining them helps in creating correct programs.
      • EK 5.1.2C - Incrementally adding tested program segments to correct working programs helps create large correct programs.
    • LO 5.1.3 - Collaborate to develop a program. [P6]
      • EK 5.1.3A - Collaboration can decrease the size and complexity of tasks required of individual programmers.
      • EK 5.1.3B - Collaboration facilitates multiple perspectives in developing ideas for solving problems by programming.
      • EK 5.1.3C - Collaboration in the iterative development of a program requires different skills than developing a program alone.
      • EK 5.1.3D - Collaboration can make it easier to find and correct errors when developing programs.
      • EK 5.1.3E - Collaboration facilitates developing program components independently.
      • EK 5.1.3F - Effective communication between participants is required for successful collaboration when developing programs.
  • EU 5.2 - People write programs to execute algorithms.
    • LO 5.2.1 - Explain how programs implement algorithms. [P3]
      • EK 5.2.1A - Algorithms are implemented using program instructions that are processed during program execution.
      • EK 5.2.1B - Program instructions are executed sequentially.
      • EK 5.2.1C - Program instructions may involve variables that are initialized and updated, read, and written.
      • EK 5.2.1D - An understanding of instruction processing and program execution is useful for programming.
      • EK 5.2.1E - Program execution automates processes.
      • EK 5.2.1J - Simple algorithms can solve a large set of problems when automated.
  • EU 5.3 - Programming is facilitated by appropriate abstractions.
    • LO 5.3.1 - Use abstraction to manage complexity in programs. [P3]
      • EK 5.3.1H - Data abstraction provides a means of separating behavior from implementation.
      • EK 5.3.1I - Strings and string operations, including concatenation and some form of substring, are common in many programs.
      • EK 5.3.1K - Lists and list operations, such as add, remove, and search, are common in many programs.
      • EK 5.3.1L - Using lists and procedures as abstractions in programming can result in programs that are easier to develop and maintain.
      • EK 5.3.1M - Application program interfaces (APIs) and libraries simplify complex programming tasks.
      • EK 5.3.1N - Documentation for an API/library is an important aspect of programming.
      • EK 5.3.1O - APIs connect software components, allowing them to communicate.
  • EU 5.4 - Programs are developed, maintained, and used by people for different purposes.
    • LO 5.4.1 - Evaluate the correctness of a program. [P4]
      • EK 5.4.1A - Program style can affect the determination of program correctness.
      • EK 5.4.1C - Meaningful names for variables and procedures help people better understand programs.
      • EK 5.4.1E - Locating and correcting errors in a program is called debugging the program.
      • EK 5.4.1F - Knowledge of what a program is supposed to do is required in order to find most program errors.
      • EK 5.4.1G - Examples of intended behavior on specific inputs help people understand what a program is supposed to do.
      • EK 5.4.1H - Visual displays (or different modalities) of program state can help in finding errors.
      • EK 5.4.1L - An explanation of a program helps people understand the functionality and purpose of it.
      • EK 5.4.1M - The functionality of a program is often described by how a user interacts with it.
  • EU 5.5 - Programming uses mathematical and logical concepts.
    • LO 5.5.1 - Employ appropriate mathematical and logical concepts in programming. [P1]
      • EK 5.5.1A - Numbers and numerical concepts are fundamental to programming.
      • EK 5.5.1D - Mathematical expressions using arithmetic operators are part of most programming languages.
      • EK 5.5.1E - Logical concepts and Boolean algebra are fundamental to programming.
      • EK 5.5.1G - Intuitive and formal reasoning about program components using Boolean concepts helps in developing correct programs.
      • EK 5.5.1H - Computational methods may use lists and collections to solve problems.
      • EK 5.5.1J - Basic operations on collections include adding elements, removing elements, iterating over all elements, and determining whether an element is in a collection.

Math Common Core Practice:

  • MP1: Make sense of problems and persevere in solving them.
  • MP2: Reason abstractly and quantitatively.
  • MP4: Model with mathematics.
  • MP7: Look for and make use of structure.

Common Core Math:

  • F-IF.1-3: Understand the concept of a function and use function notation
  • F-IF.4-6: Interpret functions that arise in applications in terms of the context

Common Core ELA:

  • WHST 12.5 - Develop and strengthen writing as needed by planning, revising, editing, rewriting
  • WHST 12.6 - Use technology, including the Internet, to produce, publish, and update writing products

NGSS Practices:

  • 2. Developing and using models

Essential Questions

  • How can computing and the use of computational tools foster creative expression?
  • How are vastly different kinds of data, physical phenomena, and mathematical concepts represented on a computer?
  • How does abstraction help us in writing programs, creating computational artifacts and solving problems?
  • How are programs developed to help people, organizations or society solve problems?
  • How are programs used for creative expression, to satisfy personal curiosity or to create new knowledge?
  • How do computer programs implement algorithms?
  • How does abstraction make the development of computer programs possible?
  • How do people develop and test computer programs?
  • Which mathematical and logical concepts are fundamental to computer programming?

Teacher Resources

Student computer usage for this lesson is: required

Lesson Plan

Session 1

Getting Started (5 min)

Introduction [3 min]

Review the string commands. As they enter the class, hand students a copy of the Warm-Up Get Ready for Lists.docx that is found in the Lesson Resources folder.

Discussion [2 min]

Discuss: What is a list? (A sequential collection of Python data values; each value is identified by an index.)

Guided Actvities (40 min)

List Role Play [20 min]

See the file calld LinkyListy Role Play in the Lesson Resources folder. Note: You can change student names to students within your class.

 

Create a human “list of students”.  See the file called LinkyListy Role Play in the Lesson Resources folder. Note: The directions below are an example.  Change student names to students within your class.

Create a List of students by starting with an empty list and modify the list by following program below.


Designate a section of the board or a poster to act as the console/printer for output and a volunteer student to act as the printer driver.


Designate an area at the front of the room for the computer memory (and future students).


As students are called by the program, have each student come up to stand in front of the room where memory resides.


Have each student point to the student that follows them to form a linked list as they come to the front.

 

LinkyListy Role Play Program:
students = []
students.append('Joe')
students.append('Pat')
students.append('Alea')
students.append('Marta')
print(students)
#add additional commands to append or insert 4 or 5 more students
print(students)
print(len(students))
print(students[3])
students.reverse()
print(students)
print('David' in students)
students.sort()
print(students)
more = ['Tom', 'Laverne']
students = students + more
print(students)
pets = ['fish'*3,'dog']
del students[1]
del students[2:4]
students.insert(0, 'Jennifer')
students = students + pets
print(students)
print(students.index('Marta'))

Check for understanding: Ask students to give an example and then explain the effect of several of the List methods. For example, students.append(“Zoe”) would add Zoe to the end of the list of students. students.insert(4, “Larry”) would add Larry at index position 4 and slide everyone else down one slot. This could be done as a placemat activity. Use different colored markers for each student to write the example. Turn placement and ask the next student to explain the effect.

Notes:

  • Length of a list: print(len(students))
  • Accessing Elements: print(students[2])
  • List Membership (in, not in): print(“Mary” in students)
  • Concatenation and repetition (+ *):Make a list of more Python commands on sentence strips. On back of the sentence strip, write the output or trace of the statement after it has executed onto the back of the card. Have one student hold the deck of cards and cycle through them. Ask students to read a card and predict the output. Meanwhile, students who are in the list will change positions to demonstrate the behavior within the list. The holder of the card provides feedback or congratulatoins in checking the correctness of classmate's responses.
  • Include cards that model these behaviors:
more = ["Tom", "Laverne"]
students = students + more
pets =['fish'*3,'dog']*2 # creates a list of ['fishfishfish','dog','fishfishfish','dog']
  • List deletion using the delete operator: del students[2], del students[2:4]
  • List deletion using the List method pop: stu = students.pop(2), stuLast = students.pop(). The pop method pops (deletes and returns) an element at a given index or the last element if no index is provided.
  • Extension: additional list methods that may be useful and interesting: sort, reverse, index, count.

Access Python Documentation [10 min]

  • Check out the Python docs for Built-in Types.
  • Go to Section 4.6 Sequence types- list, tuple, range, and check out the sections on (4.6.1) Common Sequence Operations, (4.6.3) Mutable Sequence Types, and (4.6.4) Lists.  
  • Students need to realize that Application Programmer Interfaces (APIs) are an important resource for programming.
  • Identify list methods found in the API. (Link to resource:  Python API for Built-in Types)

List Slices [10 min]

  • Quickly resurrect your list of students.
  • This time, write names on the board.  
  • To simulate list slices, add each student’s age and hair color after each student’s name.
  • Yes, lists can contain different kinds of objects!
  • Ask students to copy the list and write the code to pull out a sublist that contains the second student’s name and info.

Wrap Up (5 min)

Discussion: How are lists the same and how are they different from Strings?

Homework

Have the students do the Runestone lab activities for Lists to reinforce the above concepts. (http://interactivepython.org/runestone/static/thinkcspy/Lists/toctree.html)

Session 2

Getting Started (5 min)

  • Create a list that contains the integers from 1 to 10.
  • Create the same list from an empty list using a loop.
  • Check for understanding: create a list that counts down from 10 to 1 and then adds “Blastoff”.
  • Reverse a given list.

Guided Activities (40 min)

Lists are Mutable [20 min]

Demonstrate that lists are mutable with the following activity

  • Create a list representing a horse barn containing 4 horses in 6 stalls.
  • Use the built-in constant None for the empty stalls.
  • Find an empty stall.
  • If there is an empty stall, place “Toby” in the Barn in that slot.
  • Also. see if a particular horse is in the barn or if he is out to pasture.
  • Exchange 2 horses in the barn. (Adapted from 2012 APCS exam question 3, page 13 of  http://apcentral.collegeboard.com/apc/public/repository/ap_frq_computerscience_12.pdf)

Paired Programming [20 min]

  • In a group of 2-3, make a zoo of animals.
  • Demonstrate the use of at least 6 different list operations and methods.
  • For a bonus, try to make a story with your code.  

Wrap Up (5 min)

Homework

Create a list of 5 students that contain the students' name, age, and hair color. Use a loop to extract the information for each student and print it out.

Teacher Note: Consider using the YumYumCupcake problem (see Formative Assessment) as part of tomorrow's opening exercises. 


Options for Differentiated Instruction

  • Use a canvas shoe bag to demonstrate a list.
  • Use a parking lot with numbered spaces as an example of a list.

Evidence of Learning

Formative Assessment

  • Create a quiz similiar to the role play. Use the answer chart provided as a template for the quiz. 
  • Check for understanding: Ask students to explain what the effect of the List methods append, insert, etc. For example, students.append “Zoe” would add Zoe to the end of the list of students? Students.insert( 4, “Larry”). Would add Larry at index position 4 and slide everyone else down one slot?
  • Check for understanding: Create a list that counts down from 10 to 1 and then adds “Blastoff”.
  • Let's visit the YumYum Shoppe: Create a list that has different kinds of cupcakes and simulate the actions that might take place during a typical day. For example, yumYumCupcakes = ["chocolate mousse" *3, "vanilla creme", "strawberry fluff", "chocolate mousse"*2]. Have a customer purchase a vanilla creme cupcake if there are any, check how many chocolate mouse cupcakes are in the display case, bake some more, and add them in. Drop one cupcake on the floor and throw it away.

Summative Assessment

Paired programming: Make a zoo of animals and demonstrate the use of at least 6 different list operations and methods. Try to make a story with your code.