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

Advanced Classes
Operator Overloading

Objective

Tally how much wine is being clarified by using vectors and Operator Overloading.

After wine has been pressed it needs to be filtered and clarified, there are several barrels being filtered and the lot of it needs to be flushed. It’s important to tally how much wine is being produced so the barrels can be sealed and aged.

In order to do this you need to create vectors and add them together, these are similar to lists but are not as flexible yet more memory efficient. They are usually used for handling coordinates, in this case we will be using them like variables that hold more than one value. Adding the vectors together is done by using Operator Overloading which extends the functionality of class objects in order to use operators with them like you would on normal values.

To start off, walk and collect the metal water tins located at the top of the room, these will be used to help flush the wine being filtered in the barrels. Once collected walk to the dark X mark over the red carpet, face the barrel and begin vectorizing the contents of each barrel.

The X marks are arranged in sets of three (3) for each color carpet, a gold X mark, a light X mark and a dark X mark. On all dark and light X marks use the water() function to help flush the barrels. Also on all dark and light X marks, use theread() function to identify how much wine is being processed in that column of barrels. On the gold X mark you use the write() function to note the tally of the amounts together.

In the code editor there is a class named vector, this is used for you to not only be able to create a vector but also add it together. Create vector objects to store the data identified on light and dark X marks, for example, on red carpets red wine is being filtered:

# Create object using data from dark X mark red_wine_dark = vector(345, 272) # Create object using data from light X mark red_wine_light = vector(248, 432) # Add together vectors for totals red_wine_total = red_wine_dark + red_wine_light

In a vector, the first position is called x and the second position is y , the formula being like this: object_name = vector(x,y) . This is relevant for populating the vectors with the information acquired from the read() function.

On the gold X marks use write() function in order to write down the total for each set of vectors, for example, in the case of the red carpet X marks it’s written like this:

await player.write( "There is a total of %s pounds on the left barrels and %s pounds on the right barrels" % (red_wine_total.x, red_wine_total.y)

Remember to add .x and .y at the end of the total to identify the values of each vector.

For each set of colored carpets there is a different type of wine being filtered. On the aforementioned red carpet, red_wine is filtered; on the yellow carpets, sparkling_wine is filtered; on the green carpets, white_wine is filtered; and on the orange carpets, orange_wine is being filtered.

Once all light and dark X marks have been flushed with the water() function and all signs on the gold X marks have the totals marked down you will have completed the level.

Code book