Teacher's Guide

Chapter 8 / Level 3: More complex operations

Teaching Objective:

  • Student understands how to use the del and it’s syntax
  • Learns the practice of removing items from a dictionary
  • Understands how to adapt complex actions and operations

Guide

In this exercise the student must remove items from dictionary constants, these constants being crate1, crate2, crate3, crate4 and crate5. The items that need to be removed are: “Pipes”, “Screws” and “Bolts”.

Walk to each X mark in front of containers and use the speak() function to find out what is inside each crate. If the items “Pipes”, “Screws” or “Bolts” are present use the notation del to remove them from the list.

..........

player.speak(crate1)
del crate1["Pipes"]

..........

Do this for all five crates, find out what’s inside them and use the notation to remove the undesirables in order to complete the level.

Map overview and path

Map overview and path

Code Solution

import player

player.turn_right()
player.move_forward(4)
player.turn_right()
player.move_forward(4)
player.speak(crate1)
del crate1["Pipes"]
player.turn_right()
player.move_forward(2)
player.turn_left()
player.speak(crate2)
del crate2["Screws"]
player.turn_right()
player.move_forward(2)
player.turn_left()
player.speak(crate3)
del crate3["Screws"]
del crate3["Bolts"]
player.turn_right()
player.move_forward(2)
player.turn_left()
player.speak(crate4)
del crate4["Bolts"]
player.turn_right()
player.move_forward(2)
player.turn_left()
player.speak(crate5)
del crate5["Screws"]
del crate5["Bolts"]
del crate5["Pipes"]
Chapter 8 / Level 3: More complex operations | Teacher's Guide