Question: Problem 4 Create a new python file with the usual comment header and write code that converts time from 24 hr format to 12 hr

 Problem 4 Create a new python file with the usual comment

Problem 4 Create a new python file with the usual comment header and write code that converts time from 24 hr format to 12 hr format. You should ask the user to enter a 4 character string representing the time in 24 hr format as 'HHMM. For example, the digits '1425' indicate 14 hours and 25 minutes. You may assume that the user enters a valid time. You will need to convert the time to an integer and use the II and % operators to isolate the digits that represent the hours from the digits that represent the minutes. Note that you will be adding a colon and either am or pm to your output. For example, the output should be formatted as HH:MMxm where x is either a or p. In order to specify that an integer should be a particular number of digits when converted to a string, you can use .zfillo. For example, the integer 1 can be converted to a two-digit string with str(1).zfill(2). The resulting string would be '01'. Below are 4 examples of code execution and outputs. Be sure to handle each of these 4 cases. Please enter the time in 24hr format: 1227 12:27pm Please enter the time in 24hr format: 0002 12:02am Please enter the time in 24hr format: 0102 01:02 am Please enter the time in 24hr format: 1302 01:02 pm

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!