Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

create a pets.py module with a Pet superclass that defines common attributes - name, breed, age - where 'age' is in human years. create


create a pets.py module with a Pet superclass that defines common attributes - name, breed, age - where 'age' is in human years. create Cat and Dog subclasses that inherit from Pet and implement methods to calculate appropriate 'animal' years and print pet information. create a __repr__ method for each class that prints information about the object like so: "Name: fido, Breed: great dane, Age: 6 (44 dog yrs)" Other programs should be able to import your pets.py module and perform operations like below: . from pets import * d = Dog('fido', 'great dane', 6) c = Cat('sparky', 'siamese', 6) print(d) # should print something like "Name: fido, Breed: great dane, age: 6 (44 dog yrs)" print(c) # should print something like "Name: sparky, Breed: siamese, age: 6 (40 cat yrs)" Hints See the notes in Canvas for an example of class inheritance Each of your sub-classes will need a method to calculate non-human age. Ideally, you would name this method the same in each sub-class, Your age calculations can re-use logic from the previous Dog Years assignment, Each subclass should have it's own__repr__method to allow class-specific variation

Step by Step Solution

3.32 Rating (164 Votes )

There are 3 Steps involved in it

Step: 1

Heres the petspy module with Pet Dog and Cat classes as requested class Pet def initself name breed ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Statistics

Authors: James T. McClave, Terry T Sincich

12th Edition

9780321831088, 321755936, 032183108X, 978-0321755933

More Books

Students also viewed these Programming questions