Python* Write a Clock class that measures hours and minutes. Include the followi
ID: 3681282 • Letter: P
Question
Python*
Write a Clock class that measures hours and minutes. Include the following methods: (a) init , str . (b) Overload Addition for both clock-to-clock operations and clock-to-integer operations. If one argument is an integer, the integer is assumed to represent hours. Addition should be commutative! (c) Output should always be rounded to the minutes. (c) Use exception to handle error. If inappropriate values are passed to the constructor, the created clock instance should get a value of 0 hours and 0 minutes. Include sample code that uses your class and demonstrates the use of all methods as well as error handling.
Explanation / Answer
import time
def procedure():
time.sleep(2.5)
# measure process time
t0 = time.clock()
procedure()
print time.clock() - t0, "seconds process time"
# measure wall time
t0 = time.time()
procedure()
print time.time() - t0, "seconds wall time"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.