Teacher's Guide

Chapter 5 / Level 3: String Lists

Teaching Objective:

  • Student learns about string lists and about %s syntax
  • Understands how to use lists in a loop
  • Experiences how to combine functions, procedure and loops to complete an operation.

Guide

Walk over to the pig food and walk over it in order to grab it. Once you have it, walk to the two X marks and place the food in trays for the pigs using the place() function.

player.place(food)

After placing the food, walk to the lighter X mark and call the piglets by putting their names in a list and using a for loop containing the speak() function to call them out. The names of the piglets: "Peggle", "Peter", "Piper", "Pedro" .

To complete the level, set up the for loop and add the call message "Come here %s" inside it. By adding the x value, the for loop runs through each entry in the list until it reads out all the names.

names = ["Peggle", "Peter", "Piper", "Pedro"]

for x in names:
    player.speak("Come here %s" % x)

Map overview and path

Map overview and path

Code Solution

import player

player.turn_right()
player.move_forward(7)
player.turn_left()
player.move_forward(5)
player.place("food")
player.turn_left()
player.move_forward(4)
player.turn_right()
player.place("food")
player.turn_right()
player.move_forward(2)
player.turn_left()
names = ["Peggle", "Peter", "Piper", "Pedro"]

for x in names:
    player.speak("Come here %s" % x)
Chapter 5 / Level 3: String Lists | Teacher's Guide