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
(15) What is the best definition of a contextual tab?
katen-ka-za [31]

  1. What is the best definition of a contextual tab-<u>(c) A tab that appears in context with what you are working on</u>
  2. A theme can be applied to-<u>(d) All of the answers are correct</u>

Explanation:

  1. What is the best definition of a contextual tab-<u>(c) A tab that appears in context with what you are working on</u>
  2. A theme can be applied to-<u>(d) All of the answers are correct</u>
  3. What is the difference between Reading view and Slide Show view-<u>(c) Slide Show view contains annotation tools while Reading view does not</u>
  4. Which of the following is not a view available from the Presentation Views section of the View tab-<u>(a) Slide Show</u>
  5. Where can you find the command to access slide, note, or handout masters-<u>(d) View tab</u>
  6. To rotate a text box, which handle would you use-<u>(d) You must use the commands on the Home tab</u>
  7. To change a black and white, boring presentation into something a bit more pleasing to the eye, what option would be best-<u>(b) Templates</u>
  8. The area on the top of your PowerPoint screen, as seen in the image, is commonly referred to as the what-<u>(a) Menu Options</u>
  9. What does it mean when a command button is grayed out-<u>(c) The command is disabled and requires an action first.</u>
  10. The area on a slide that holds text that will appear in the presentation outline is a-<u>(a) text box</u>
  11. To easily find a presentation that you were working on earlier today, you could-(<u>c) all of the above</u>

6 0
3 years ago
A persons decision to take action without being asked is
Nimfa-mama [501]

Answer:

Initiative

Explanation:

Initiative: the power or opportunity to act or take charge before others do.

5 0
3 years ago
Which of the following is the single best rule to enforce when designing complex passwords?
saw5 [17]

Answer:

B. Longer passwords

Explanation:

If the password is longer, it requires more incorrect attempts to find it, so the system could identify a potential hacker attempt. Smaller but more complex passwords could be identified by mistype or forgotten passwords.

3 0
3 years ago
Why coaxil cable called coxial cable ?
Reika [66]

Answer: Coaxial Cable has got two physical channel layer in same axis of the cable that is why it is known as "coaxial cable".

Explanation: Coaxial cable is the main example for television cable and telephone cable that have two physical layer of channels and are separated by a insulating material layer and the outer layer working a ground section.The axis of both the physical layer are present on the same axis of the cable and thus is known as coaxial cable. They cable is usually made up of copper and some other materials.

7 0
3 years ago
Read 2 more answers
If you weigh 100 pounds, and your 150 pound big sister is sitting 15 feet from the fulcrum of a seesaw, how far from the fulcrum
Dahasolnce [82]

Answer:

22.5

Explanation:

My weight = 100 pounds

Sister's weight = 150

Distance from fulcrum = 15 ft

Distance has an inverse proportion with weight

Distance = k/w

Where k is a constant

K = distance x weight

K = 100 x distance

150 x 15 = 100 distance

2250 = 100 distance

Divide through by 100 to get distance

2250/100 = distance

Distance = 22.5

5 0
3 years ago
Other questions:
  • What does FTP stand for?
    15·2 answers
  • Samantha writes technical content for a webpage and uploads it to the webpage. What should she do to ensure that the content, wh
    11·2 answers
  • What type of encoding is this?<br>0x6a656c6c7966697368<br>cause I'm trying to decode it
    5·1 answer
  • You resurrected an old worksheet. It appears to contain most of the information that you need, but not all of it. Which step sho
    5·1 answer
  • Programming assignment (100 pts): In the C++ programming language write a program capable of playing Tic-Tac-Toe against the use
    14·1 answer
  • failure of the _ cylinder will often result in sudden unexpected loss of the ability to stop the vehicle
    10·1 answer
  • In client server network, there is no central server //// true or false​
    8·1 answer
  • Functions of barriers include (mark all that apply): A. Define boundaries B. Design layout C. Deny access D. Delay access
    10·1 answer
  • Please help me on this coding problem :)
    6·1 answer
  • Which automatic startup option should you choose when windows' startup fails immediately after installing a new driver but befor
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!