Teacher's Guide

Chapter 8 / Level 2: Using a dictionary

Teaching Objective:

  • Student learns how to use the plant() function
  • Understands how dictionaries interface with functions
  • Learns the convivence of using Dictionaries in certain circumstances instead of other iterators like lists

Guide

In this exercise there is a constant named seeds that holds the value for 4 different crop seeds. These are “Pumpkin” , “Eggplant” , “Tomato” and “Melon”. In order to complete the level walk to each X mark and use the plant() function to plant all seeds in their respective area. Use the water() function to water the crops afterwards.

.......

player.plant(seeds, "Pumpkin")
player.water()

.......

player.plant(seeds, "Eggplant")
player.water()

.......

player.plant(seeds, "Tomato")
player.water()

.......

player.plant(seeds, "Melon")
player.water()

Lastly head for the middle light X mark and use the speak() function to count out all the seeds you planted in the field.

player.speak(seeds)

Map overview and path

Map overview and path

Code Solution

import player

player.turn_left()
player.turn_left()
player.move_forward(2)
player.turn_left()
player.move_forward(2)
player.plant(seeds, "Eggplant")
player.water()
player.turn_left()
player.turn_left()
player.move_forward(4)
player.plant(seeds, "Tomato")
player.water()
player.turn_left()
player.turn_left()
player.move_forward()
player.turn_right()
player.move_forward(5)
player.turn_right()
player.move_forward()
player.plant(seeds, "Melon")
player.water()
player.turn_left()
player.turn_left()
player.move_forward(4)
player.plant(seeds, "Pumpkin")
player.water()
player.turn_left()
player.move_forward(3)
player.turn_left()
player.move_forward(2)
player.speak(seeds)
Chapter 8 / Level 2: Using a dictionary | Teacher's Guide