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 22:10
Asequential circuit contains a register of four flip-flops. initially a binary number n (0000 ≤ n ≤ 1100) is stored in the flip-flops. after a single clock pulse is applied to the circuit, the register should contain n + 0011. in other words, the function of the sequential circuit is to add 3 to the contents of a 4-bit register. design and implement this circuit using j-k flip-flops.
Answers: 1
question
Computers and Technology, 23.06.2019 00:00
What engine component is shown in the above figure?
Answers: 1
question
Computers and Technology, 23.06.2019 03:50
Q-1 which of the following can exist as cloud-based it resources? a. physical serverb. virtual serverc. software programd. network device
Answers: 1
question
Computers and Technology, 23.06.2019 07:00
What are three software programs for mobile computing?
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
Mathematics, 11.04.2020 01:34
question
Mathematics, 11.04.2020 01:34
Questions on the website: 13722367