Beginner Coding with Blocks
Chapter
>
Level
Lists and Collections
Assigning list values
Objective
Determine how many eggs of each color were lain and incubated by each chicken by assigning list values.
The chickens have lain several eggs which were placed in incubators, find out which chicken laid the eggs and how many of each color. The names of the chickens and the different types of colored eggs have been stored in two (2) different string lists which are constants: chickens and eggs.
Numeric lists are also created for each of the three (3) different egg colors using the create list with block: red_eggs, blue_eggs, and white_eggs, each initialized with four zeros (use four number blocks with value 0). These are set up so we may fill them with amounts of each egg laid. The four entries represent each of the four chickens that laid eggs. These can be set as variables for ease of calling later using the set variable block: susan = 0, kelly = 1, betty = 2, sandy = 3.
Walk to the dark X marks next to the incubators and use the speak block to determine which chicken laid eggs of that color. Each incubator has a constant with a message outlining the amounts, those being: red_incubator, blue_incubator and white_incubator. Read the message in each incubator of the correct colored egg using the speak block with the constant variable.
Once you read a message, add the number of eggs laid to the colored egg list. Do this by using the set item in list block. Connect the colored egg list (e.g., red_eggs), the index (e.g., kelly which equals 1), and the value (e.g., 2). For example: if the message says "Kelly laid 2 Red eggs", use set item in list with red_eggs, index kelly (or 1), and value 2.
Once you have successfully read all the messages and added the amounts to the colored eggs lists, walk to the light X mark, face the table and use a for loop block provided in the editor to read out all the names and amounts of eggs incubated in order to complete the exercise.