Question: PYTHON ASSIGNMENT Problem: (1) The __init__ method should initialize the values of the instance variables. Here is the beginning of __init__ : def __init__(self, the_hr,
PYTHON ASSIGNMENT
Problem:
(1) The __init__ method should initialize the values of the instance variables. Here is the beginning of __init__:
def __init__(self, the_hr, the_min, the_sec): self.hr = the_hr # Also initialize min and sec.
(2) Include a __str__ method that returns the current state of the clock object as a string. You can use the string format method format like this:
return "{0:02d}:{1:02d}:{2:02d}".format(self.hr, self.min, self.sec) (3) When the tick method is executed, add one to sec. If the resulting value of sec is 60, set it back to 0 and update min and hr if necessary. Here is the beginning of the tick method:
def tick( ): self.sec += 1 if self.sec == 60: self.sec = 0 self.min += 1 # Also check if self.min == 60 and # and if self.hr == 0.
(4) Write testing code in test1.py to test your class. Use this import statement at the top:
from clock import Clock
(5) Also write a unit test file (test2.py file) for all of the methods in your Clockclass using assert statements.
(6) If you have time, add yr, mon, and day instance variables, modify the tickmethod to accomodate them.
Clock + hr int min: int + sec int (the_hr int, the_min: int, the_sec int) +str tick) ( ) : strStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
