Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(ANSWER USING PYTHON 3.6) In this homework you will design a class Dog and save it in a file named dog . py . (

(ANSWER USING PYTHON 3.6)

In this homework you will design a class Dog and save it in a file named dog.py. (Important hint: when you change the file dog.py the changes will not be reflected in an old shell, even if you import dog again. Start a new shell to test your changes.)

Problem 1. Write a class definition line and a one line docstring for the class Dog. Write an __init__ method for the class Dog that gives each dog its own name and breed. Make sure that you test this on a successful creation of a dog object. For example,

>>> import dog >>> sugar = dog.Dog('Sugar', 'border collie') >>> sugar.name Sugar >>> sugar.breed border collie Problem 2. Add a list attribute tricks to each dog and initialize it in __init__ to the empty list. (The user does not have to supply a list of tricks when creating a dog.) Make sure that you test this successfully.

>>> sugar.tricks []

Problem 3. Write a method teach as part of the class Dog. The method teach should add a passed string parameter to tricks and print a message that the dog that knows the trick.

>>> sugar.teach('frisbee') Sugar knows frisbee

Problem 4. Write a method knows as part of the class Dog. The method knows should check whether a passed string parameter is in the dogs list of tricks, print an appropriate message and return True or False.

>>> sugar.knows('frisbee') Yes, Sugar knows frisbee True >>> sugar.knows('arithmetic') No, Sugar doesn't know arithmetic False

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions