Beginner Coding with Blocks
Chapter
>
Level

Lists and Collections
Numeric Lists

Lists can be used to store multiple values in a single place, be it numbers or word strings! This will save you time and space in your code as well as be able to read data in sequences.

In this exercise, grab all the colored eggs around the barn and store them in a list so you can place them together in a container.

Guide

Objective

Grab eggs and populate a list you can store in a container.

Grab the different eggs in the barn, and store them together in a list so you may place them together inside a container.

Lists are like variables that allow you to store multiple values together in a single place. Use the create empty list block to create a new list. Then use the set item in list block with INSERT mode at LAST position to add values to it. Connect the list variable to the list input and the value you want to add to the TO input.

Grab all the eggs of each color in the field and create variables: blue_eggs, red_eggs, green_eggs using the set variable block. Count how many eggs you've collected of each type and store them in these variables (for example: blue_eggs = 5).

Create a list named eggs using the create empty list block. With this set up, you can add the variables to the list using the set item in list block with INSERT mode at LAST position. Connect eggs to the list input and each variable (blue_eggs, red_eggs, green_eggs) to the TO input. Be sure to add them in the same order of color listed above and as provided in the code editor.

Once all eggs are inside the list, head for the X mark and place them inside the container using the place block with the eggs variable connected to it.

Code book