A | Assignment |
Please save your solutions for Exercises 1 to 2 in a Python script named unit09__ex(1-2)code.py
.
Save the script in the unit09
folder, compress the folder into a .zip
file, and upload it to ILIAS.
For more information, please visit the following link:
https://geomoer.github.io/moer-base-python/unit00/unit00-04_submission_guidelines.html
Make sure your code is clearly structured and includes comments where helpful.
Tasks
🔥 Base class Animal
Please use the same Animal
class from the exercises unit09.
1️⃣ Create a subclass called Bird
- This subclass should inherit all attributes and methods from
Animal
. - Add a new method named
fly()
, which prints a message describing how high the bird can fly. This message should include the animal’s name and mention the approximate flying height (e.g., “Eagle can fly up to 3,000 meters high.”).
2️⃣ Create another subclass called Reptile
- This subclass should also inherit from
Animal
. - Add a new method named
crawl()
, which prints a message describing how the reptile moves on the ground (for example, “Python moves by slithering smoothly across the ground.”). - Add another method named
length()
, which prints a message stating the length of the reptile (for example, “Python is about 6 meters long.”).
Instructions
- Use
super()
to call the constructor of the parent class if needed. - Make sure each method includes a descriptive and meaningful message.
- Create at least one object from each subclass and try calling all the methods to check that everything works as expected.
Extra Challenge
Try to think of even more specific methods that fit birds or reptiles and add them if you like!