subject

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 dog’s 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

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 13:30
1. technician a says horsepower information can be used by consumers to compare the power of different automobile engines. technician b says that manufacturers will often list the horsepower output of their engines in the online service information. who is right?
Answers: 2
question
Computers and Technology, 23.06.2019 02:00
Which of the following is not a source of sustainable raw materials? a) coal mine b) flick of sheep c) cotton plantation d) line forest.
Answers: 2
question
Computers and Technology, 23.06.2019 04:31
Selling a product through an electronic medium is
Answers: 1
question
Computers and Technology, 24.06.2019 02:10
Which sentences describe the things you need to ensure while creating a sketch and a drawing? while an artistic or creative drawing is a creative expression, a technical drawing is an informative expression. you need to create accurate and neat drawings to convey accurate information. a technical drawing clearly conveys its meaning or information, and does not leave room for interpretation maintain a good speed while creating drawings
Answers: 1
You know the right answer?
In this homework you will design a class dog and save it in a file named dog. py. (important hint:...
Questions
question
History, 08.01.2021 19:30
question
Mathematics, 08.01.2021 19:30