Question: wrting programing python PLE HELP ME BY PYTHON, THIS IS ONE PROBLEM BUT IT 'S SO LONG. THANKS U SO MUCH PLE HELP ME BY

wrting programing python

PLE HELP ME BY PYTHON, THIS IS ONE PROBLEM BUT IT 'S SO LONG. THANKS U SO MUCH

wrting programing python PLE HELP ME BY PYTHON, THIS IS ONE PROBLEM

BUT IT 'S SO LONG. THANKS U SO MUCH PLE HELP ME

BY PYTHON Read everything before doing anything! Create a class named Clock

PLE HELP ME BY PYTHON

Read everything before doing anything! Create a class named Clock to represent a time in hours and minutes. (I am using the name clock because there is an existing module named time and I want to avoid conflicts.) Store this class in a file named clock.py. As hinted in the previous paragraph, objects of this class have two attributes that must be named hour and minute. The hour ranges from 0 to 23, and the minute from 0 to 59. Your class will implement the following methods: _init__(self, hour, minute) The constructor creates a new clock with the given hour and minute. Your constructor must ensure that, no matter what numbers are given the hour is from 0 and 23 and the minute from 0 and 59. Thus, if someone tries this: import clock t1 = clock.clock(19, 12) t2 = clock.clock(-5, 74) The first object represents the time 7:12 p.m. The second object has bad input, so do whatever you feel is reasonable to create a valid time. My code creates a clock representing 5:14 a.m. from the bad input. (Hint: I used abs and %to force the numbers into the range I wanted.) _str__(self) This method returns a string representing the time in 24-hour European notation; so this code: import clock t = clock.clock(17, 8) t2 = clock.clock (3, 45) print(t) print(t2) Produces this output: 1708 8345 add(self, other) This method returns a new clock object that is the result of adding the two times. For example: import clock t1 = clock.clock(2, 37) # 2:37 a.m. t2 = clock.Clock(5, 29) # 5:29 a.m. t3 = t1.add(t2) print(t3) # prints 0896. subtract(self, other) This method returns a new clock object that is the result of subtracting the two times. For example: import clock t1 = clock.clock(18, 20) t2 = clock.Clock(3, 45) t3 = t1.subtract(t2) print(t3) # prints 1435 Your method should always subtract the smaller time from the larger time, so if I had written t3 - t2.subtract(t1) would have gotten the same result. Hint: you can use abs to make your life easier. The next two functions must be declared before the class declaration. The next two functions must be declared before the class declaration. from_military(s) This function takes a string that has a military time in it as its argument and returns a new clock object with the corresponding time. You might use it as follows: import clock t = clock.from_military( '1546) print(t) # output will be 1546 from_as_pm(s) This function takes a string that has a time in AM/PM format it as its argument and returns a new clock object with the corresponding time. You might use it as follows: import clock t = clock.from_am_pm (3:46 p.m.) print(t) # output will be 1546 Your function must accept the AM or PM in upper or lower case, with or without periods, but you may presume there will be at least one space after the digits. Testing Your Code Download the clocktest.py program and put it in the same directory with your clock.py module. When you run the test program, it will do a fixed set of computations. It will then repeatedly prompt you to enter two times (one in military format, another in AM/PM format), add them, and subtract them

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!