Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions