Question
PYTHON: There are 24 hours in a day, but we all think about them differently. Some people and places in the world work with a
PYTHON:
There are 24 hours in a day, but we all think about them differently. Some people and places in the world work with a 24-hour clock that goes from 0:00 to 23:59, while others work with a 12-hour clock that goes from 12:00AM to 11:59PM.
24-hour clock: 0:00 (midnight) 12:00 (noon) 23:59 (one minute before midnight).
12-hour clock: 12:00 AM (midnight) 12:00 PM (noon) 11:59 PM (one minute before midnight).
You are going to be given the hours and minutes in 24 hour time and convert the value to 12-hour time. For now, we will leave off the AM"/"PM designation.
Hint: You are going to need more than one if statement.
Details
Input
The program takes in the following input:
hourhour: an integer value, from 0 to 23, representing the hour in the day in 24-hour time.
minutesminutes: an string value, from 00 to 59, representing the minutes after that hour.
You might rightly be asking yourself why Im giving you minutes as a string! Think about it (play with it even!) What happens if I give you minutes between 00 and 09? Not convinced, try it! Im just making life a bit easier.
Processing
You will convert the hour, given by the variable hourhour, to the appropriate 12-hour clock time as follows:
if the value of hourhour is 0, you must change it to 12 (as 0:mm on the 24-hour clock represents 12:mm AM on the 12-hour clock).
If the value of hourhour is 13 or more, you will have to subtract 12 from that number so that the hour meets the criteria of a 12-hour clock.
Output
Note that full output will be of the form:
24-hour time: HH:mm
12-hour time: hh:mm
END OF OUTPUT
Most of that is taken care of for you.
You will output the appropriate 12-hour clock time as defined above, where hh represents the hour (possibly one or two digits) and MM represents the minutes after that hour (always 2 digits).
THE CODE PROVIDED:
hour = int(input()) minutes = input()
print("24-hour time: ", hour, ":", minutes, sep="") #======================================= # PLEASE START YOUR WORK HERE #=======================================
#======================================= # PLEASE END YOUR WORK HERE #======================================= print("12-hour time: ",hour,":",minutes, sep="") print("END OF OUTPUT")
Examples Sample input Sample output 0:00 12:00 8:17 8:17 11:35 11:35 12:00 12:00 13:01 1:01 17:29 5:29
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started