Python Development Course
Chapter
>
Level

Basic Operators
Add and Subtract

Objective

Collect eggs and balance the books by adding and subtracting their quantities.

It’s time to collect some eggs in the nesting grounds, walk over and grab the various eggs in the field so we can document how many eggs were lain. Of all the eggs laid there are four (4) eggs that are no good, red eggs however hold twice the nutrition as regular eggs. Document how many good eggs you have, and what their nutritional value is.

First walk over all the eggs to collect them, then make three (3) variables for each type of egg: white_eggs, dark_eggs, red_eggs. In these variables add the amount of eggs you’ve gathered of each type.

Once you’ve collected everything, walk to the dark X marks and document all the eggs that are good from this batch. Use the speak() function to announce the number by adding (+) together the three variables you created and subtracting (-) the number of eggs that are bad from this batch, in this format: player.speak(white_eggs + dark_eggs + red_eggs - 4) .

After you’re done documenting the amount of eggs you have this batch, head for the light X mark and check what the nutritional value is of each egg is. First you need to subtract the bad eggs from each variable, there are two (2) bad white eggs, one (1) bad dark egg, one (1) bad red egg that needs to be removed, like this:

white_eggs -= 2 dark_eggs -= 1 red_eggs -= 1

Next up multiply the red_eggs by two (2) because their nutritional value is double like this: red_eggs *= 2 . Then use the speak() function at the X mark and add (+) together all the variables with their new values to complete the level.

Code book