Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this homework you will design a class Dog and save it in a file named dog . py . ( Important hint: when you

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

Problem 5. Create a data attribute species as part of the class Dog and set its value to 'canis familiaris'. The method species should be defined within the class Dog but outside of any method.

>>> dog.Dog.species 'Canis familiaris' >>> sugar.species 'Canis familiaris'

Plese explain your code for each problem, line by line if possible

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

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions

Question

dy dx Find the derivative of the function y=(4x+3)5(2x+1)2.

Answered: 1 week ago

Question

Draw and explain the operation of LVDT for pressure measurement

Answered: 1 week ago

Question

=+working on a micro-multinational?

Answered: 1 week ago

Question

=+j Identify the challenges of training an international workforce.

Answered: 1 week ago