Python Development Course
Chapter
>
Level

Using Dictionaries
Using a dictionary

Objective

Plant seeds in the field by using a dictionary.

Seeds need to be planted in the field in order for crops to grow, there are 4 distinct types of crops to be planted: “Pumpkin” , “Eggplant” , “Tomato” and “Melon”. You are in possession of these seeds which are stored in dictionary named seeds, a pre-declared constant.

Walk to the X marks and use the function plant() to sow the seeds in the field, this function takes two arguments, one that states the name of the dictionary and one that states the index of the seed.

For example: player.plant(seeds, "Pumpkin") this code plants the seeds for Pumpkins, we put the name of the dictionary first followed by the name of the crop. The code will display the number of seeds over the character’s head and reveal the number of seeds in the dictionary.

Water the crops after they are planted, do this for all four different crops in the field. Afterwards walk to the middle X mark and use the speak() function to call out the number of all seeds that were planted.

Code book