Recall that time in military format is based on a 24 hour clock. For example, 2:30pm...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Recall that time in military format is based on a 24 hour clock. For example, 2:30pm is 1430 in military format, 2:30am is 0230, 12:00am (midnight) is 0000 and 12:00pm (noon) is 1200. Note that the military time is always represented with four digits. In this problem, you are asked to write two functions to convert between the two formats. They are described below: (10 points) Write a function called ampm_to_military with a single parameter ampm_time, which is a string representing the time in AM/PM format. The function returns a string, which is the corresponding time in military format. The string ampm.time must have the following format to be valid: the hour (one or two characters), followed by a colon, followed by the minute (exactly two characters), followed by the letters "am" or "pm" (both upper and lower case are allowed). Thus, the length of the string ampm time should be either 6 or 7. Furthermore, the hour and minute should correspond to legitimate values. Your function should first check for the validity of ampa.time. If invalid, print an appropriate message and return the empty string. If it is valid, return the corresponding military time as a string of four characters. • (10 points) Write a function called military.to.ampm with a single parameter mil_time, which is a string representing the time in military format. The function returns a string, which is the corresponding time in AM/PM format. The string mil.time must have the following format to be valid: it must be exactly four characters long, with the hour as the first two characters and the minute as the next two characters. In addition, the hour and minute should correspond to legitimate values. As in the above function, your function should first check for the validity of mil.time. If invalid, print an appropriate message and return the empty string. If it is valid, return the corresponding AM/PM time as a string of 6 or 7 characters. You will find the following Python string methods/functions useful here: The string method isdigit() returns True if all characters in the string are digits and there is at least one character, and False otherwise. For example, if astr="0345", antr.indigit() returns True. But if astr "aB9", astr.indigit() returns False. The function int (antr) returns the integer corresponding to the string antr. If astr has non-digit characters, you will get an error message. The function str (N) returns the string corresponding to the integer N. Here are some sample runs. >>> from problemi import. >>> military_to_ampa("1542") 3:42pm >>> ampa to military("9:06am") 0905 Here are some sample runs. >>> from problemi import >>> military_to_ampm("1542") 3:42pm >>> ampa_to_military (*9:05am") 0905 >>> ampm to military ("9:05pm") 2106 >>> ampm_to_military("9: 5pm") 9: 5pm in an invalid AM/PM timo! >>> military_to_ampm("3623") 3623 is an invalid military time! >>> military_to_ampm ("0005") 12:05am >>> nampm to military("11:65pm") 11:65pm is an invalid AM/PM timo! >>> ampa_to_military ("II:35pm) II:35pm is an invalid AM/PM time! Recall that time in military format is based on a 24 hour clock. For example, 2:30pm is 1430 in military format, 2:30am is 0230, 12:00am (midnight) is 0000 and 12:00pm (noon) is 1200. Note that the military time is always represented with four digits. In this problem, you are asked to write two functions to convert between the two formats. They are described below: (10 points) Write a function called ampm_to_military with a single parameter ampm_time, which is a string representing the time in AM/PM format. The function returns a string, which is the corresponding time in military format. The string ampm.time must have the following format to be valid: the hour (one or two characters), followed by a colon, followed by the minute (exactly two characters), followed by the letters "am" or "pm" (both upper and lower case are allowed). Thus, the length of the string ampm time should be either 6 or 7. Furthermore, the hour and minute should correspond to legitimate values. Your function should first check for the validity of ampa.time. If invalid, print an appropriate message and return the empty string. If it is valid, return the corresponding military time as a string of four characters. • (10 points) Write a function called military.to.ampm with a single parameter mil_time, which is a string representing the time in military format. The function returns a string, which is the corresponding time in AM/PM format. The string mil.time must have the following format to be valid: it must be exactly four characters long, with the hour as the first two characters and the minute as the next two characters. In addition, the hour and minute should correspond to legitimate values. As in the above function, your function should first check for the validity of mil.time. If invalid, print an appropriate message and return the empty string. If it is valid, return the corresponding AM/PM time as a string of 6 or 7 characters. You will find the following Python string methods/functions useful here: The string method isdigit() returns True if all characters in the string are digits and there is at least one character, and False otherwise. For example, if astr="0345", antr.indigit() returns True. But if astr "aB9", astr.indigit() returns False. The function int (antr) returns the integer corresponding to the string antr. If astr has non-digit characters, you will get an error message. The function str (N) returns the string corresponding to the integer N. Here are some sample runs. >>> from problemi import. >>> military_to_ampa("1542") 3:42pm >>> ampa to military("9:06am") 0905 Here are some sample runs. >>> from problemi import >>> military_to_ampm("1542") 3:42pm >>> ampa_to_military (*9:05am") 0905 >>> ampm to military ("9:05pm") 2106 >>> ampm_to_military("9: 5pm") 9: 5pm in an invalid AM/PM timo! >>> military_to_ampm("3623") 3623 is an invalid military time! >>> military_to_ampm ("0005") 12:05am >>> nampm to military("11:65pm") 11:65pm is an invalid AM/PM timo! >>> ampa_to_military ("II:35pm) II:35pm is an invalid AM/PM time!
Expert Answer:
Answer rating: 100% (QA)
Python program to create and test the functions ampmtomilitary and militarytoampm which converts the time from AMPM format to military and viceversa Python version 36 def ampmtomilitaryampmtime Functi... View the full answer
Related Book For
Understanding Basic Statistics
ISBN: 9781111827021
6th Edition
Authors: Charles Henry Brase, Corrinne Pellillo Brase
Posted Date:
Students also viewed these programming questions
-
In this exercise, you are asked to write the functionality of a generic shopping basket; you will use this in several subsequent project exercises. Write a set of JSP pages that displays a shopping...
-
In this simulation, you are asked to address equations related to the accounting for equity. Prepare responses to all parts. Explanation (a) Explain why common stock is classified as part of equity....
-
In this simulation, you are asked to address questions related to the accounting for share options and earnings per share computations. Prepare responses to all parts. Explanation On the basis of the...
-
When VGS = 0.5 VGS(off) . gm. is -------------- the maximum value. Select one: a. one-fourth b. three-fourths c. equal to d. one-half
-
Machinery purchased for $52,000 by Carver Co. in 2008 was originally estimated to have a life of 8 years with a salvage value of $4,000 at the end of that time. Depreciation has been entered for 5...
-
What is the probability of obtaining twelve tails in a row when flipping a coin? Interpret this probability. The probability of obtaining twelve tails in a row when flipping a coin is (Round to five...
-
John Alexander is considering putting money into the following investments: a. A $10,000.00, five-year certificate of deposit earning 4.5% interest compounded annually b. A $2,500.00, seven-year...
-
A condensed balance sheet for a partnership to be liquidated is as follows: The profit and loss percentages for Partners A, B, and C are 50%, 30%, and 20%, respectively. For each of the following...
-
Given the following information, leverage will add how much value to the unlevered firm per dollar of debt? Corporate tax rate: 3 4 % ; personal tax rate on income from bonds: 3 0 % ; personal tax...
-
While I think of it, you need to prepare a memo (C-2-1) addressing the following issues: 1. Describe the two forms of accounts receivable confirmation requests that you used and indicate the factors...
-
Performance Task 3 HINT If you need help with this task, please access the FNSACC421 Tutor Assist_Performance Task 3.pdf. This document breaks down the steps to complete the task, as well as provides...
-
Describe the four procedures that can be used in conducting tests of controls.
-
What is the purpose of tests of controls?
-
You are a shareholder in a listed company and are told that last year the companys net profit after tax increased from 100m to 130m, and that the management of the company is therefore performing...
-
Sampling is more likely to be used for certain types of tests of controls. What types are these?
-
For what types of procedures would sampling be appropriate?
-
Part 1: Searching and sorting an int array Instructions: Write a program called RandomGrades.java that generates integers representing student grades, sorts the list in descending order, and searches...
-
A business had revenues of $280,000 and operating expenses of $315,000. Did the business (a) Incur a net loss (b) Realize net income?
-
Do you want to own your own candy store? With some interest in running your own business and a decent credit rating, you can probably get a bank loan on start-up costs for franchises such as Candy...
-
(a) Make a tree diagram to show all the possible sequences of answers for three multiple-choice questions, each with four possible responses. (b) Probability Extension Assuming that you are guessing...
-
Consider a data set of 15 distinct measurements with mean A and median B. (a) If the highest number is increased, what is the effect on the median and mean? Explain. (b) If the highest number is...
-
Match each of the following roles of a cost management system, 1 through 6 , with the most appropriate example, a through \(f\). Cost Management System Role 1. Develop accurate product/ service costs...
-
A cost management system is made up of three primary elements: (1) motivational elements, (2) informational elements, and (3) reporting elements. Classify each of the following items, a through...
-
Stock options and stock grants are often utilized to compensate executives. The general rule is that the fair value of the compensation award is determined at the grant date and expense is recognized...
Study smarter with the SolutionInn App