Computer Science

Write a program that reads from user — (i) an hour between 1 to 12 and (ii) number of hours ahead. The program should then print the time after those many hours, e.g.,
  Enter hour between 1-12 : 9
  How many hours ahead : 4
  Time at that time would be : 1 O'clock

Python

Python Control Flow

57 Likes

Answer

hr = int(input("Enter hour between 1-12 : "))
n = int(input("How many hours ahead : "))

s = hr + n

if s > 12:
    s -= 12

print("Time at that time would be : ", s, "O'clock")

Output

Enter hour between 1-12 : 9
How many hours ahead : 4
Time at that time would be :  1 O'clock

Answered By

25 Likes


Related Questions