Python Development Course
Chapter
>
Level

Classes and Objects
Class Functions

Objective

Refill the water and food for the cows by activating the functions inside the pump objects next to their trays.

The cows could use some more food and water, you don’t have any on you but thankfully there are automatic pumps that can refill nourishment for them.

The machines located on either side of the trays are pumps, they are assigned a class named machine . Inside this class a function is present named refill() that can replenish your choice of either "food" or "water" .

class machine: def refill(self, resource ): if resource == "food": player.place(resource) player.speak(food_amount) if resource == "water": player.water() player.speak(water_amount)

You can address the refill() function in an object of this class in the same manner you would a function for the player, like this:

pump = machine() # Establish the object pump.refill("food") # Execute the object function

Using this function you are able to refill nourishment for the cows, walk to the light X marks in order to refill "water" and walk to the dark X marks in order to refill "food" .

Refill all four (4) trays in the field to complete your objective and provide nourishment for the animals.

Code book