Computers and Technology
Computers and Technology, 03.12.2019 06:31, evafaith

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

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 10:00, michael3592
When is an original work considered public domain? a. when posted via social media b. when it is posted on the internet c. when a copyright symbol is not included with the piece of work d. when explicit permission is given by the author / owner
Answers: 1
image
Computers and Technology, 22.06.2019 10:50, whocares1234
A911 dispatcher is the sole sender of messages to all police officers. while on patrol, officers communicate with the dispatcher who, in turn, relays messages to other officers. the officers do not communicate directly with one another. this illustrates a network.
Answers: 1
image
Computers and Technology, 22.06.2019 23:30, bri2008
Which of the following is not a symptom of chronic fatigue syndrome
Answers: 2
image
Computers and Technology, 23.06.2019 01:50, akornegay2
Write a program that uses a random number generator to generate a two digit positive integer and allows the user to perform one or more of the following operations: a. double the number. b. reverse the digits of the number. c. raise the number to the power of 2, 3, or 4. d. sum the digits of the number. e. if the number is a two-digit number, then raise the first digit to the power of the second digit. f. if the number is a three-digit number and the last digit is less than or equal to 4, then raise the first two digits to the power of the last digit. after performing an operation if the number is less than 10, add 10 to the number. also, after each operation determine if the number is prime. each successive operation should be performed on the number generated by the last operation. your program should not contain any global variables and each of these operations must be implemented by a separate function. also, your program should be menu driven. 7. (fraction calculator) write a program that
Answers: 1
Do you know the correct answer?
In this homework you will design a class dog and save it in a file named dog. py. (important hint:...

Questions in other subjects: