Question: (1) Modify the Cat class in inClass5 to a Dog Class and add a breed as an argument for the __init__(self, breed) function. For the

(1) Modify the Cat class in inClass5 to a Dog Class and add a breed as an argument for the __init__(self, breed) function. For the class exercise, we use a function setColor(self, color) to set the color attribute (instead of using the __init__() ) , and getColor(self) to retrieve the object color. Add the __str__(self) method to return the specified object attributes class Dog: # The init method or constructor def __init__(self, breed): # Instance Variable self.breed = breed # self.color = " " # you can set the color attribute here as well. # comment it out for now. In the Dog class, add three functions (def) def setColor(self, color): # this creates a instances variable self.color = color # Retrieves instance variable def getColor(self): return self.color def __str__(self): return (f' breed: {self.breed}, color: {self.color} ') - Create two Dog objects: roger, sue to initialize their breed as pug and lab - Since there is only one argument in the __init__(self, breed), you use the setColor function for the color attribute. Write the rest of the program to generate the following: rodger's color is green sue's color is pink Dog roger: breed: pug, color: green Dog sue: breed: lab, color: pink -

(2) Add class variables (animal) to the Dog class and use __init__(self, breed, color) to initialize the instance variables. The class variable (outside of the __init__(...) method, but in the class Dog: definition. (see the following) class Dog: # Class Variable animal = 'global animal' # Class variable!!! # use __init__(self, breed, color) to initialize the two attributes (breed, and color) # add def __str__(self) to return the animal, breed, color attributes For the program: - Create two dog objects: roger (pug, green) , buzo (lab, pink) - Display the objects (print(object) ) - Display the Dog class attribute - Assign the class variable from global animal to stuff animal - Display the class attribute again - Display Dog.animal, buzo.animal, and roger.animal and their id(object_name) locations o All the 3 addresses should be the same - Assign roger.animal = roger animal - Display roger.animal and its address again.... See the change of id address - Assign Dog.animal = D_dog - Display the addresses of the Dog.animal and buzo.animal .... See the different. Your final results: roger details: roger is a global animal, breed: Pug, color: green buzo details: buzo is a global animal, breed: Bulldog, color: pink Accessing class variable using class name the Dog class is: global animal change the class variable Dog.animal to = stuff animal now Dog.animal is stuff animal address is 1814372944240 buzo,animal is: stuff animal address is 1814372944240 roger.animal is : stuff animal address is 1814372944240 change roger to a 'roger animal', address before the change is 1814372944240 roger is now a roger animal address is also changed.... 1814617881264 The Dog class attribute is,D_dog, with address 1814617881008 buzo,animal is: D_dog address is 1814617881008 The following exercises focus on files (input/output): creating, writing, and reading a file. A file can be anywhere in permanent storage media (USB stick, disk, remote drive...). For simplicity, for this exercise, all the files at located in the current source code (program) directory. (dont worry about the file path details for now)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!