Teacher's Guide

Chapter 8 / Level 4: Placing objects using dictionaries

Teaching Objective:

  • Student familiarizes themselves with the many applications of dictionaries
  • Understands how to isolate dictionary values and use them with functions
  • Learns when best to use dictionaries as opposed to other storage formats

Guide

In this exercise the student must grab all the crops on the field and place them in the storeroom. There are four (4) types of crops on the field that need to be gathered, those being: "corn" , "carrot", "wheat" and "parsnip". Once you collect all crops store them in a dictionary named crops and add in the number of items you’ve collected of each crop.

crops = {}
crops["corn"] = 6
crops["carrot"] = 4
crops["wheat"] = 7
crops["parsnip"] = 10

Once all crops are stored in the dictionary, walk towards each X mark and store the crops in containers using the place() function.

player.place(crops["corn"])
.......
player.place(crops["wheat"])
.......
player.place(crops["parsnip"])
.......
player.place(crops["carrot"])

Each X mark is accompanied by a sign outlining the type of crop, place the crops in the correct containers in order to complete the level.

Map overview and path

Map overview and path

Code Solution

import player

player.turn_left()
player.turn_left()
player.move_forward(5)
player.turn_left()
player.move_forward(3)
player.turn_right()
player.move_forward()
player.turn_right()
player.move_forward(4)
player.turn_left()
player.move_forward(5)
player.turn_left()
player.move_forward(3)
player.turn_right()
player.move_forward()
player.turn_left()
player.move_forward()
player.turn_right()
player.move_forward()
player.turn_left()
player.move_forward(5)
player.turn_left()
player.move_forward()
player.turn_right()
player.move_forward()
player.turn_left()
player.move_forward(8)
crops = {}
crops["corn"] = 6
crops["carrot"] = 4
crops["wheat"] = 7
crops["parsnip"] = 10
player.turn_left()
player.move_forward(3)
player.turn_left()
player.move_forward(2)
player.turn_left()

player.place(crops["corn"])
player.turn_right()
player.move_forward(2)
player.turn_left()
player.place(crops["wheat"])
player.turn_right()
player.move_forward()
player.place(crops["parsnip"])
player.turn_right()
player.move_forward(3)
player.turn_left()
player.place(crops["carrot"])
Chapter 8 / Level 4: Placing objects using dictionaries | Teacher's Guide