Unit 2. Developing Programming ToolsRevision Date: Jul 26, 2017 (Version 2.1.1)
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.
Student computer usage for this lesson is: required
In the Lesson Resources folder:
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.
Discuss: What is a list? (A sequential collection of Python data values; each value is identified by an index.)
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 = 
#add additional commands to append or insert 4 or 5 more students
print('David' in students)
more = ['Tom', 'Laverne']
students = students + more
pets = ['fish'*3,'dog']
students = students + pets
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.
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.
more = ["Tom", "Laverne"]
students = students + more
pets =['fish'*3,'dog']*2 # creates a list of ['fishfishfish','dog','fishfishfish','dog']
del students, del students[2:4]
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.
Discussion: How are lists the same and how are they different from Strings?
Have the students do the Runestone lab activities for Lists to reinforce the above concepts. (http://interactivepython.org/runestone/static/thinkcspy/Lists/toctree.html)
Demonstrate that lists are mutable with the following activity
Nonefor the empty stalls.
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.
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.
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.