Teacher's Guide
Chapter 5 / Level 5: Referencing list items
Teaching Objective:
- Student understands how to reference items in a list
- Understands how to use lists with
whileloops - Learns list syntax and how to best utilize it when calling up specific items
Guide
In this exercise you must collect and check the contents of an egg basket before distributing them in various containers in the map while using lists.
First grab the basket by the containers in the field, walk to the light X mark to check the eggs in the basket. Use a while loop to go through all of the contents, the content is displayed via two list constants named: eggs, which has the names of the types of each egg, and basket which houses the number of each type of egg found in the basket.
count = 0
while count < 4:
player.speak("I have %d %s in compatment %d"
% (basket[count],eggs[count],count) )
count += 1
The eggs of each of the four (4) types are stored in compartments in the basket ranging between 0 and 3 . They are stored in the following order:
0 = white eggs
1 = dark eggs
2 = red eggs
3 = blue eggs
This is also the order in which the eggs are stored in the lists. Now that you confirmed the contents, walk to each of the four dark X marks and store the eggs in containers. The containers have signs above them detailing the color of egg that goes there.
Use the place() function to store the eggs, use the lists and the position of each egg color in the list to locate and store the correct one. You can express a specific value within a list by wring the name of the list followed by the position of the items within the list, for example: basket[0] .
player.place(basket[0]) # White Eggs
........
player.place(basket[3]) # Blue eggs
........
player.place(basket[1]) # Dark Eggs
........
player.place(basket[2]) # Red eggs
Place all the eggs in their respective containers using this format in order to complete the level.
Map overview and path

Code Solution
import player
player.turn_left()
player.move_forward(4)
player.turn_left()
player.move_forward(6)
player.turn_right()
count = 0
while count < 4:
player.speak("I have %d %s in compatment %d"
% (basket[count],eggs[count],count) )
count += 1
player.turn_right()
player.move_forward(2)
player.turn_right()
player.move_forward()
player.place(basket[0])
player.turn_left()
player.move_forward(3)
player.turn_right()
player.place(basket[3])
player.turn_right()
player.turn_right()
player.move_forward(3)
player.place(basket[1])
player.turn_left()
player.move_forward(3)
player.turn_right()
player.place(basket[2])