In: Computer Science
Python : Write the function inAWhile that takes two integers t and d, where t is the present time on a 12-hour clock, rounded to an integer (so t is an integer in the interval [1,12]) and d is an integer increment in hours, and returns the time on a 12-hour clock in d hours. For example, in 2 hours from 3 o’clock, it will be 5 o’clock, so inAWhile (3, 2) = 5. Notice that 12 is followed by 1 on a 12-hour clock, since only computer scientists start counting at 0. The test data will clarify. Additionally, you should guarantee that the type of the parameters is int, using an assertion. For example, inAWhile (‘Hi’, ‘there’) should fail the assertion, and inAWhile (5, ‘there’) should also fail the assertion.
PYTHON CODE:
def inAWhile(t,d):
# checking the parameters types and report
error
assert isinstance(t,int) and isinstance(d,int)
,"t and d must be integer"
# finding the total of d and t
total=t+d
# checking for total greater than 12
if total > 12:
# checking for 12
when subtracting 12 from 12
if total - 12 ==
12:
return 12
else:
# returning the time in 12 hours format
return (total -12) % 12
else:
# return the sum of t
and d when total is less than 12
return t + d
# testing
if __name__=='__main__':
print(inAWhile(10,5))
print(inAWhile(3,2))
print(inAWhile(1,1))
print(inAWhile(12,11))
print(inAWhile(8,8))
SCREENSHOT FOR CODING:
SCREENSHOT FOR OUTPUT: