1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nataliya [291]
3 years ago
6

Write a program that inputs a time from the console. The time should be in the format "HH:MM AM" or "HH:MM PM". Hours may be one

or two digits, for example, "1:10 AM" or "11:30 PM". Your program should include a function that takes a string parameter containing the time. This function should convert the time into a four-digit military time based on a 24-hour clock. For example, "1:10 AM" would output "0110 hours", "11:30 PM" would output "2330 hours", and "12:15 AM" would output "0015 hours". The function should return a string to main for writing it out to the console. (Do not output the value in the function.) Sample runs of the program:
Computers and Technology
1 answer:
monitta3 years ago
5 0

Answer:

  1. def processTime(timeStr):
  2.    timeData = timeStr.split(" ")
  3.    timeComp = timeData[0].split(":")
  4.    h = int(timeComp[0])
  5.    m = int(timeComp[1])
  6.    
  7.    output = ""
  8.    if(timeData[1] == "AM"):
  9.        if(h < 10):
  10.            output += "0" + str(h) + str(m) + " hours"
  11.        elif(h == 12):
  12.            output += "00" + str(m) + " hours"
  13.        else:
  14.            output += str(h) + str(m) + " hours"
  15.    else:
  16.        h = h + 12  
  17.        output += str(h) + str(m) + " hours"
  18.    return output  
  19. print(processTime("11:30 PM"))

Explanation:

The solution code is written in Python 3.

Firstly, create a function processTime that takes one input timeStr with format "HH:MM AM" or "HH:MM PM".

In the function, use split method and single space " " as separator to divide the input time string into "HH:MM" and "AM" list items (Line 2)

Use split again to divide first list item ("HH:MM") using the ":" as separator into two list items, "HH" and "MM" (Line 3). Set the HH and MM to variable h and m, respectively (Line 4-5)

Next create a output string variable (Line 7)

Create an if condition to check if the second item of timeData list is "AM". If so, check again if the h is smaller than 10, if so, produce the output string by preceding it with a zero and followed with h, m and " hours" (Line 9 - 11). If the h is 12, precede the output string with "00" and followed with h, m and " hours" (Line 12 - 13). Otherwise generate the output string by concatenating the h, m and string " hours" (Line 14 -15)

If the second item of timeData is "PM", add 12 to h and then generate the output string by concatenating the h, m and string " hours" (Line 17 -18)

Test the function (Line 22) and we shall get the sample output like 2330 hours

You might be interested in
Mechanisms that combine memory, processing speed, and knowledge to regulate the analysis and flow of information within the info
gizmo_the_mogwai [7]

Answer:

control processes.

Explanation:

Mechanisms that combine memory, processing speed, and knowledge to regulate the analysis and flow of information within the information-processing system are referred to as executive/control processes.

3 0
2 years ago
Is the computer a device that calculates and has the independence and initiative for the actions it performs?
inna [77]

Answer:

The answer is "True".

Explanation:

In this question, the given statement is true because the computer is a device that receives information as input, analyzes information utilizing a program that provides relevant information for the processed data, and in this, it performs numerous calculation and all the calculation will be store in its memory, which is used in the future for collect data on hard drives.

8 0
2 years ago
100 POINTS!!! PLEASE HELP ME
Ronch [10]

Answer:

1 web

2- invintory

3- spreadsheet

4-survey

Explanation:

hope it helps

5 0
2 years ago
Read 2 more answers
The faster alcohol is consumed, the faster it reaches the __________.
Anni [7]
The faster it reaches the bloodstream

6 0
3 years ago
Read 2 more answers
Simplify the Boolean expression (AB(C + BD) + AB]CD.
finlep [7]

Explanation:

Simplify the Boolean expression (AB(C + BD) + AB]CD.

6 0
2 years ago
Read 2 more answers
Other questions:
  • Tower defense is included under which genre of game
    15·2 answers
  • If you find yourself boxed in by a vehicle on your left or right _____________
    14·2 answers
  • Which part of a fax cover sheet helps the recipient verify the successful transmission of all the pages? A) REMARKS: be) TOTAL N
    7·2 answers
  • If in your checkout cart right before you buy something there is an option saying "this order contains a gift." on amazon, what
    7·1 answer
  • Consider the formula: G=D+(A+C^2)*E/(D+B)^3 Show the order that a processor would follow to calculate G. To do so, break down th
    10·1 answer
  • How can the function abcfunc change the address in its local copy of intpoint?
    11·1 answer
  • (20points)
    6·1 answer
  • Find the median and mean of the data set below: 29 17 40 12 29
    6·1 answer
  • The cameras picture review function allows you to look at the _ you've taken
    8·1 answer
  • you want to run your campaign for your dry-cleaning service across three different publishers, each with different video creativ
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!