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
62 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
28 Likes
Related Questions
A store charges ₹120 per item if you buy less than 10 items. If you buy between 10 and 99 items, the cost is ₹100 per item. If you buy 100 or more items, the cost is ₹70 per item. Write a program that asks the user how many items they are buying and prints the total cost.
A year is a leap year if it is divisible by 4, except that years divisible by 100 are not leap years unless they are also divisible by 400. Write a program that asks the user for a year and prints out whether it is a leap year or not.
Write a Python script that asks the user to enter a length in centimetres. If the user enters a negative length, the program should tell the user that the entry is invalid. Otherwise, the program should convert the length to inches and print out the result. There are 2.54 centimetres in an inch.
Write a program that asks the user for two numbers and prints Close if the numbers are within .001 of each other and Not close otherwise.