CBSE Class 11 Computer Science
Question 126 of 161
Flow of Control — Question 3
Back to all questions 3
Question Question 3
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
Solution
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