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
Where do you go to create a workbook?​
Over [174]

Answer:

The explaination of this question is given below in the explanation section

Explanation:

The following steps are used to create a workbook.

1- Go to start menu and search about EXCEL (application software) and then click on it to open.

If you already opened a EXCEL's workbook, and you want to create a new workbook, then you follow the following steps:

  1. Click the File tab.
  2. Click New.
  3. Under Available Templates, double-click Blank Workbook. Keyboard shortcut To quickly create a new, blank workbook, you can also press CTRL+N.

A new workbook will be created.

6 0
3 years ago
How bridges are built over water
Black_prince [1.1K]
It’s all depending on what method
4 0
2 years ago
When you enable user access control (uac)
SVEN [57.7K]
The UAC is on by default. So, you don't need to turn it on unless someone else turned it off.

The UAC has four modes.

The lowest mode is the off position. If the UAC is off, no UAC prompt will pop up when doing administrative tasks.

6 0
3 years ago
What are the two access modes that are used when opening a file for input and output when pickling?
san4es73 [151]

The two access modes that are used when opening a file for input and output when pickling are rb and wb.

<h3>What is pickling?</h3>

Pickle is generally used in Python to serialize and deserialize a Python object structure. In other words, it is the act of transforming a Python object into a byte stream in order to save it to a file/database, maintain program state across sessions, or transport data over a network. By unpickling the pickled byte stream, the original object hierarchy can be recreated. This entire procedure is comparable to object serialization in Java or .Net.

When a byte stream is unpickled, the pickle module first makes an instance of the original object before populating it with the right data. To accomplish this, the byte stream only carries data relevant to the original object instance.

To learn more about python visit:

brainly.com/question/13437928

#SPJ4

8 0
1 year ago
How do you view a presentation as your audience would see it?
Nutka1998 [239]
<h3>Answer:</h3>

Option B is the correct answer.

=> By clicking slideshow button.

<h3>Explanation:</h3>

A view in which audience should see the presentation is the SLIDE SHOW VIEW.

Slide show can be started by clicking on the Slide show tab than choose one of the desired option/ways to SET UP SLIDE SHOW.

<h3>I HOPE IT WILL HELP YOU!</h3>
5 0
3 years ago
Read 2 more answers
Other questions:
  • Question 1 (1 point)
    10·2 answers
  • Shelly tells a friend that her computer needs to be fixed because it has been producing a lot of heat and is smoking. Where is t
    10·1 answer
  • Describe the positive and negative effects of Internet​
    6·2 answers
  • Which of the following information should be included in audit documentation? a. Procedures performed. b. Audit evidence examine
    13·1 answer
  • PLEASE ANSWER ASAP
    7·1 answer
  • What are the reasonsfor documenting business rules​
    6·1 answer
  • Does anyone know a working free spotify premium on ios 2021 plz i have had any luck finding anything:(​
    15·2 answers
  • Blockchain is often associated with Bitcoin and the financial services industry. However, it is applicable to almost every indus
    13·1 answer
  • What are 3 customizations that can be done using the header/footer section in the customize reports tray?.
    14·1 answer
  • write a function named get majority last name that accepts as its parameter a dictionary from strings to strings the keys of the
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!