Beginner Coding with Blocks
Chapter
>
Level

Advanced Lists and Data Structures
Using Lists for Objects

Objective

Harvest all the crops on the field and store them in the storeroom using nested lists.

There are four (4) crops growing on the field: "corn", "carrot", "wheat" and "parsnip". Harvest the crops and place them in the storeroom by setting up a nested list structure (dictionary).

Walk through the field and grab all the crops, once you've successfully navigated through the field. Count the number of each type of crop and store the crops in a nested list structure, for ease of handling and storage.

First create a variable named crops using the create empty list block or by using the set dict value block. Use the set dict value block to add each crop name as a key and the number of crops you've grabbed as the value. For example: use set dict value with crops, key "corn", and value 6 (the number of corn you collected).

Once you've grabbed all the crops and placed them inside the nested list structure, walk to the X marks and face the crates to place the crops in storage using the place block. Use the get dict value block to access the crop values, like this: use get dict value with crops and key "corn", then connect it to the place block. Each X mark has a sign informing you of the crop that is stored there. Complete the level by storing the crops in the correct storage crates as marked by the signs.

Code book