Live coding today! We will design and implement classes for various animals (
Parrot). What is an appropriate hierachy? What class and instance attributes do we need? Can we have default values for some attributes? What methods do we need and which ones should we override?
There is no new reading assigned, but be sure to review the slides and your notes from the last two lectures so that you're ready to start applying what was discussed. Then read the slides and the skeleton file below and think about the questions asked. We'll complete the implementation of the classes together in lecture.
Penguinare for you to implement)
Zooand lets you interact with the animals. You can play a little at the zoo, and then read the code to see how we use
Animaland its subclasses.
Answers to the questions on slides 6, 8, and 9 are D, D, and B, respectively.
Complete the file zoology.py by implementing the subclasses
Penguin. You can design them as you wish--this is just for practice--but you can use the ideas below if you want to match your code to ours, which
we will post on May 6th is now posted:
speak) it always asks for a cracker ("Now give me a cracker!")
After you complete the class definitions, check out this module that sets up a zoo! The given module creates a
Zoo and lets you interact with the animals. You can play a little at the zoo, and then read the code to see how we use
Animal and its subclasses.