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
The director of security at an organization has begun reviewing vulnerability scanner results and notices a wide range of vulner
gayaneshka [121]

Answer:

D. Network vulnerability database

Explanation:

A database management system (DBMS) can be defined as a collection of software applications that typically enables computer users to create, store, modify, retrieve and manage data or informations in a database. Generally, it allows computer users to efficiently retrieve and manage their data with an appropriate level of security.

In this scenario, The director of security at an organization has begun reviewing vulnerability scanner results and notices a wide range of vulnerabilities scattered across the company. Most systems appear to have OS patches applied on a consistent basis but there is a large variety of best practices that do not appear to be in place. Thus, to ensure all systems are adhering to common security standards a Network vulnerability database, which typically comprises of security-related software errors, names of software, misconfigurations, impact metrics, and security checklist references should be used.

Basically, the Network vulnerability database collects, maintain and share information about various security-related vulnerabilities on computer systems and software programs.

5 0
3 years ago
What impact download speeds on different computers
solong [7]

Answer:

They're connected in different ways.

Explanation:

Speeds will vary by connection type. Ethernet (often called wired) is almost always faster than wireless.

7 0
3 years ago
What provides access to the internet?
Sphinxa [80]
A router!
12345678901234567890
6 0
3 years ago
13. By adding built-in writable memory to its cartridge, Nintendo’s _________________ was the first console game that gamers cou
Rzqust [24]

The answer is c
Explanation:
5 0
3 years ago
Which of the following scenarios describes an IT professional using the Internet and computer system access in an unprofessional
pantera1 [17]

Answer:

All of the above

Explanation:

6 0
2 years ago
Other questions:
  • Steve is proofreading his memo and he notices that he has typed a phrase twice. Steve should _____.
    5·2 answers
  • 4. What aspect of the initial database planning process would the formula (0 + Pt × 3 + p)/5 be used in?
    5·1 answer
  • What are 2 ways that technology can negatively impact the environment.
    8·2 answers
  • Hello, can you help me answer these questions?
    9·2 answers
  • A service provider, hardware, and web browser are needed to connect to __________.
    8·2 answers
  • Consider a system consisting of m resources of the same type, being shared by n processes. Resources can be requested and releas
    13·1 answer
  • Va rog urgent
    8·1 answer
  • WHAT IS A GOOD APP FOR REMOVING VIRUSES AND IT YOU DONT HAVE TO PAY MUCH FOR IT ????? PLEASE HELP ME
    8·2 answers
  • According to programming best practices, how should you handle code that needs to be repeated several times in a program?
    6·1 answer
  • Which of the following statements is true about the code used for software development?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!