Beginner Coding with Blocks
Chapter
>
Level
Advanced Lists and Data Structures
Looping through Lists
Objective
Recover all materials in the field and run inventory of all collected items before putting them away in specific containers.
A storm wrecked the outpost by the bridge scattering materials everywhere, I'm sure those materials can be used for later. Run inventory of each of the objects you pick up and put them away in the storeroom across the bridge.
First collect all debris scattered in the field, those being: "branches", "boulders" and "planks". Once you have collected all the items place them in a nested list structure (dictionary) named materials and add all three (3) of the material names and quantities inside it using the set dict value block.
Once everything is placed inside the nested list structure, head for the light X mark and run inventory on all of the materials you've gathered using the for each in dictionary block with the speak function. This special loop block allows you to iterate over nested list structures (dictionaries) by providing two variables: one for the key (name) and one for the value (number).
Use the for each in dictionary block with variables name and number, and the materials dictionary. Inside the loop, use the speak block with a text join block to combine "There were ", the number variable, " ", the name variable, and " collected".
After running inventory, walk to the dark X marks and store the materials you've gathered in the nested list structure inside containers using the place block. Use the get dict value block to access each material, like get dict value with materials and key "branches", then connect it to the place block. There are three (3) dark X marks, on the left container place the "branches", in the middle container place the "boulders" and in the right container place the "planks". Put everything away in the correct position in order to complete the level.