Teacher's Guide
Chapter 6 / Level 3: Checking for existence
Teaching Objective:
- Student understands how to check for existence
- Learns how to combine a series of actions and conditions with loops
- Learns how to use the
len()function
Guide
Grab all the items in the field that you can grab, these will be lettuce and tomatoes. Once you grab all the items head for the X mark in front of the containers and retrieve the remaining items using the collect() function. Use a for loop and check if “carrots” and “cucumbers” can be collected.
for x in range(4):
player.move_forward(2)
player.turn_left()
if "carrot" or "cucumber" in bag:
player.collect(bag[x])
player.turn_right()
Once all items are collected, store the items in a list:
items = []
items.append(2) # carrots
items.append(2) # tomato
items.append(6) # lettuce
items.append(2) # cucumbers
Once you have stored all the items, head for the light X mark and check if you have all items in the list before combining them. You do this by using len() operator and < or > to check if list is complete and then use combine()
if len(items) < 5:
player.combine(items)
Map overview and path

Code Solution
import player
player.turn_left()
player.move_forward(5)
player.turn_right()
player.move_forward(3)
player.turn_right()
player.move_forward()
player.turn_right()
player.move_forward(3)
player.turn_left()
player.move_forward()
player.turn_left()
player.move_forward(3)
player.turn_right()
player.move_forward(9)
player.turn_left()
player.move_forward(3)
player.turn_left()
for x in range(4):
player.move_forward(2)
player.turn_left()
if "carrot" or "cucumber" in bag:
player.collect(bag[x])
player.turn_right()
player.move_forward(2)
player.turn_left()
items = []
items.append(2)
items.append(2)
items.append(6)
items.append(2)
if len(items) < 5:
player.combine(items)