In: Computer Science
Many people keep time using a 24 hour clock (11 is 11am and 23 is 11pm, 0 is midnight). If it is currently 13 and you set your alarm to go off in 50 hours, it will be 15 (3pm). Write a Python program to solve the general version of the above problem. Ask the user for the time now (in hours), and then ask for the number of hours to wait for the alarm. Your program should output what the time will be on the clock when the alarm goes off.
Using python
# Python program to print when the time when alarm is going to turn off
# Getting the inputs from User
presentTime = int(input("Enter current time: "))
turnoffTime = int(input("Enter a Turn Off time: "))
# presentTime is the current time of the system in 24 hour format 13 for example
#turnoffTime is the time after which the alarm is going to Off 50 for example
shutdownTime= presentTime+(turnoffTime % 24)
# The time at which Alarm is going to turn off is given by the above equation
# for the given example shutdownTime is 13+(50%24) = 13+2 = 15
if(shutdownTime < 24): #Since the time doesn't exceed 24 we taken this if eLse loop
print("Alarm goes Off at: ",shutdownTime," hours")
else:
print("Alarm goes off at: ",shutdownTime-24," hours")
output: