Coding for KidsCoding for Kids
Creative LevelsChallengesTeacher's Guide
Vote for features
Advanced Python Development Course
Chapter
>
Level

Advanced Lists
Modifying a Matrix

Objective

Collect and store wine bottles on the wine rack by modifying a Matrix.

There are several wine bottles that need to be stored in a wine rack. However there are several bottles already stored in the rack, the items need to be placed in specific locations in order to be put away.

The bottles on the rack are stored in a Matrix, a type of Nested List. Matrixes are Nested Lists where each item is a list with the exact same length, this creates a sort of grid where items become divided in rows and columns. For example:

matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], [0, 0, 0] ]

In the code above we have a Matrix with three (3) columns and four (4) rows. To access an item inside the Matrix, all you need to do is state the row and column where the item is located similar to how you would access items on a standard list but with two entries rather than one. For example, based on the code above: matrix[0][0] = 1 , matrix[0][1] = 2 , matrix[1][0] = 4 , etc.

There are four (4) different types of wine bottles in the cellar, those being: "purple bottle" , "green bottle" , "blue bottle" , "yellow bottle" . Grab all the bottles on the field so they may be stored on the rack.

There are also bottles stored inside crates, walk to the light X marks and use the collect() function while facing the crates to grab the bottles. There are two constants that hold the contents of the crates: lower_crate and upper_crate . Their names correspond to their position on the map and are used as follows: player.collect(lower_crate) .

Once all bottles have been collected place the number of bottles you’ve collected for each type into variables, these being: purple_bottle , green_bottle , blue_bottle , yellow_bottle . Afterwards walk to the gold X mark and face the wine rack.

On the code editor a Matrix named wine_rack will be displayed, look for the items in the Matrix that hold 0 as a value and add the bottles you’ve collected to those values. The Matrix will have the color of bottle that needs to be added outlined in each row. To add a new item to the Matrix, type the row and column where you’d like the value to be placed, for example: wine_rack[0][1] = purple_bottle .

Remember all lists positions start at 0 , once all items are added to the Matrix and it’s complete. Use the place() function followed by speak() function on the gold X mark with the name of the Matrix to ascertain it’s value and complete the level, like this: player.place(wine_rack) , player.speak(wine_rack).

Code book