Teacher's Guide

Chapter 8 / Level 1: Creating a dictionary

Teaching Objective:

  • Student learns dictionary syntax
  • Learns common use for dictionaries
  • Understands how Dictionaries are different from lists

Guide

To complete the level walk through the field and grab all the fruit, those being “Apples” , “Oranges” and “Pears” . Store these in a dictionary named bag, with the index being the name of the fruit and the value being how many you’ve grabbed.

bag = {}
bag["Apples"] = 3
bag["Oranges"] = 4
bag["Pears"] = 6

Once you’ve grabbed the fruits and put them inside the dictionary, walk to the X mark and use the speak function to count all the different fruits you’ve grabbed and their quantities.

player.speak(bag)

Map overview and path

Map overview and path

Code Solution

import player

player.turn_left()
player.move_forward(6)
player.turn_left()
player.move_forward(3)
player.turn_left()
player.move_forward()
player.turn_right()
player.move_forward(4)
player.turn_left()
player.move_forward(3)
player.turn_left()
player.move_forward(2)
player.turn_right()
player.move_forward()
player.turn_left()
player.move_forward(3)
player.turn_right()
player.move_forward()
bag = {}
bag["Apples"] = 3
bag["Oranges"] = 4
bag["Pears"] = 6
player.turn_right()
player.turn_right()
player.move_forward(3)
player.turn_left()
player.move_forward(6)
player.speak(bag)
Chapter 8 / Level 1: Creating a dictionary | Teacher's Guide