Teacher's Guide
Chapter 7 / Level 4: Using lists in functions
Teaching Objective:
- Student understands how to use lists inside custom functions
- Understands how to synchronize lists and pair them together using functions
- Is able to consolidate complex sequences in functions
Guide
In this exercise, the student must gather all vegetables in the field and take them to press, identified by the X mark, so you may pickle them by using a custom function.
To do this you must first set up a custom function to allow you to execute the command.
def pickle_food(food,amount)
for x in range(3):
player.speak("You have pickled %d %s" % (amount[x], food[x]))
This function uses two (2) lists as arguments, one for a list containing the names of the food you wish to pickle and one for the number of that item you wish to pickle.
Once the custom function is set up, gather all the vegetables in the field, create the list for the food names titled vegetables and store the types in the lists, the vegetables being : "Cucumbers" , "Tomatoes" and "Radishes".
vegetables = []
vegetables.append("Cucumbers")
vegetables.append("Tomatoes")
vegetables.append("Radishes")
Then do the same with the numbers list, create a list named vegetable_number . Create variables for each type of vegetable and store how many vegetables of that type you’ve gathered then put them in the list.
cucumbers = 5
tomatoes = 3
radishes = 4
vegetables_number = [cucumbers, tomatoes, radishes]
Once the lists are set up, head for the X mark and pickle the vegetables in order to complete the level.
pickle_food(vegetables,vegetables_number)
Map overview and path

Code Solution
import player
def pickle_food(food, amount):
for x in range(3):
player.speak("You have pickled %d %s" % (amount[x], food[x]))
player.turn_left()
player.turn_left()
player.move_forward(8)
player.turn_right()
player.move_forward(3)
player.turn_right()
player.move_forward(6)
player.turn_left()
player.move_forward(3)
player.turn_left()
player.move_forward(6)
player.turn_right()
player.move_forward(3)
vegetables = []
vegetables.append("Cucumbers")
vegetables.append("Tomatoes")
vegetables.append("Radishes")
cucumbers = 5
tomatoes = 3
radishes = 4
vegetables_number = [cucumbers, tomatoes, radishes]
pickle_food(vegetables, vegetables_number)