Class Clock:
def __init__(self):
self._hours = 12
self._minutes = 0
self._seconds = 0
def getHours(self):
return self._hours
def getMinutes(self):
return self._minutes
def getSeconds(self):
return self._seconds
def show(self):
print "%d:%02d:%02d" % (self._hours, self._minutes, self._seconds)
I want to add a method to this class called setTime which takes hours, minutes, and seconds as parameters and make appropriate changes to the object’s attributes. The following code makes use of this class and the method setTime.
clk = Clock()
clk.setTime(12, 34, 2)
print clk.getHours()
clk.show()
def setTime(self, hours = 12, minutes = 34, seconds = 2):
self._hours = hours
self._minutes = minutes
self._seconds = seconds
My question is whether my setTime method is correct? Also, how to check whether my function is correct or not?