Teacher's Guide
Chapter 7 / Level 1: Exception Handling
Teaching Objective:
- Students learn what exception handling is and how errors can be addressed in code
- Learn the syntax of
try/exceptcode block sequences - Understand how troubleshooting can make coding easier and more efficient
Guide
In this exercise we will be working with exception handling, this is the process of which you catch errors by using try / except code blocks allowing you to run the code even if the error would normally stop the game from running.
There are several items that need to be collected, assembled into kits and stored into crates as part of emergency supplies. This items are: water cans , "thread" , "blue blanket" , "red blanket" and "green blanket" . First collect the three (3) colored blankets at the top of the map, then walk to the light X mark and use the collect() function to grab "thread" from the crate.
player.collect("thread")
Once collected, head to the bottom of the map and grab the cans of water, then move to the dark X mark over the blue carpet.
Now that all items are collected, assemble them into kits so they may be stored into the crates. First assemble the water and thread into sets:
water_can = 2
thread = 3
Assemble the kits by combining the items and naming the kits their respective colors according to both the blankets you collected and carpets on the floor..
blue_kit = water_can + thread + "blue blanket"
red_kit = water_can + thread + "red blanket"
green_kit = water_can + thread + "green blanket"
This will unfortunately yield an error, but you can easily address this by using the try / except code blocks. This will in case of an error, switch out the code for one that achieves the intended result without causing an error.
try:
blue_kit = water_can + thread + "blue blanket"
except:
blue_kit = water_can + thread + 1
try:
red_kit = water_can + thread + "red blanket"
except:
red_kit = water_can + thread + 1
try:
green_kit = water_can + thread + "green blanket"
except:
green_kit = water_can + thread + 1
Do this for the red_kit and the green_kit as well to clear all errors. Once done, walk to the dark X marks and place() all the colored kit variables in the crates corresponding to the colors of the carpets in order to complete the level.
player.place(blue_kit)
........
player.place(green_kit)
........
player.place(red_kit)
Map overview and path

Code Solution
import player
player.turn_left()
player.move_forward(3)
player.turn_left()
player.move_forward(4)
player.turn_right()
player.move_forward(2)
player.turn_left()
player.move_forward(3)
player.turn_right()
player.move_forward()
player.collect("thread")
player.turn_right()
player.move_forward(7)
player.turn_right()
player.move_forward()
player.turn_right()
player.move_forward(2)
player.turn_right()
player.move_forward(3)
water_can = 2
thread = 3
try:
blue_kit = water_can + thread + "blue blanket"
except:
blue_kit = water_can + thread + 1
try:
red_kit = water_can + thread + "red blanket"
except:
red_kit = water_can + thread + 1
try:
green_kit = water_can + thread + "green blanket"
except:
green_kit = water_can + thread + 1
player.place(blue_kit)
player.turn_left()
player.move_forward()
player.turn_right()
player.place(green_kit)
player.turn_left()
player.move_forward()
player.turn_right()
player.place(red_kit)
player.turn_left()
player.move_forward()
player.turn_right()