Question: So far, we can create a new Clock object, but we can't do anything with it . Next, we need to define additional operations that

So far, we can create a new Clock object, but we can't do anything with it. Next, we need to define additional operations that can be performed on our Clock objects. We added three methods that can be used to extract the individual components of the data contained in the object, and three methods to adjust or shift the seconds stored in the objects.
class Clock:
def __init__(self, hr, min, sec):
self.hours = hr
self.minutes = min
self.seconds = sec
def get_hours(self):
return self.hours
def get_minutes(self):
return self.minutes
def get_seconds(self):
return self.seconds
def shift_seconds(self, sec):
if sec >0 and self.seconds + sec <60:
self.seconds += sec
return self.seconds
return 'Unsuccessful operation'
We can use the new methods to extract and print the values of one of the objects we just created:
>>> hrsA = clockA.get_hours()
>>> minA = clockA.get_minutes()
>>> clockB.shift_seconds(10)
>>> display = f'Clock time is {hrsA} hour(s) and {minA} minute(s)'
>>> display
'Clock time is 12 hour(s) and 59 minute(s)'
Which of the following retrieves the seconds from clockB?
Group of answer choices
clockB.get_seconds()
clockA.get_seconds(clockB)
clockB.get_seconds(self)
Clock.get_seconds()

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 Programming Questions!