1

Use Python and please comments every step. [25] 6. Write a program that reads from standard...

Question

Use Python and please comments every step. [25] 6. Write a program that reads from standard...
use Python and please comments every step.
[25] 6. Write a program that reads from standard input, two times in military format and prints the number of hours and minut
[25] 6. Write a program that reads from standard input, two times in military format and prints the number of hours and minutes between the two times. Assume that the second time is always ahead of the first time. You should avoid using conditional statement (if-else) for this program. Your program must query the user for the two times and output the difference based on the two sample runs given below. Please enter the first time: 0900 Please enter the second time: 1730 Difference between the two times: 8 hours and 30 minutes. Please enter the first time: 1730 Please enter the second time: 0900 Difference between the two times: 15 hours and 30 minutes.

Answers

CodeToCopy:

timediff.py

#python 2.7

# taking time1 from user

time1 = raw_input("Please enter the first time: ")

# taking time2 from user

time2 = raw_input("Please enter the second time: ")

# convertin them as integers

time1 = int(time1)

time2 = int(time2)

# fetching minutes from the time1

mins1 = time1 % 100

# fetching minutes from the time2

mins2 = time2 % 100

# fetching hours from the time1

hours1 = time1/100

# fetching hours from the time2

hours2 = time2/100

# calculating hour difference between time2 and time1

diff_hours = (hours2 - hours1) % 24

# minute difference between time2 and time1

diff_mins = (mins2 - mins1);

# if minute difference is less than 0, hours need to be reduced by 1 to

# get actual hour difference

diff_hours = (diff_hours, diff_hours-1) [ diff_mins < 0]

# finalizing the range of minute difference time2 and time1

diff_mins = diff_mins % 60

# printing difference between two times

print("Difference between the two times: " + str(diff_hours) + " hours and " + str(diff_mins) + " minutes.")

timediff.py

#python 3.x

# taking time1 from user

time1 = input("Please enter the first time: ")

# taking time2 from user

time2 = input("Please enter the second time: ")

# convertin them as integers

time1 = int(time1)

time2 = int(time2)

# fetching minutes from the time1

mins1 = time1 % 100

# fetching minutes from the time2

mins2 = time2 % 100

# fetching hours from the time1

hours1 = time1/100

# fetching hours from the time2

hours2 = time2/100

# calculating hour difference between time2 and time1

diff_hours = (hours2 - hours1) % 24

# minute difference between time2 and time1

diff_mins = (mins2 - mins1);

# get actual hour difference

diff_hours = (diff_hours, diff_hours-1) [ diff_mins < 0]

# finalizing the range of minute difference time2 and time1

diff_mins = diff_mins % 60

# printing difference between two times

print("Difference between the two times: " + str(diff_hours) + " hours and " + str(diff_mins) + " minutes.")

OutputScreenshot:

File Edit View Search Terminal Help ashok@ashok-VirtualBox:~/Desktop/personal/python$ python timediff.py Please enter the fir

File Edit View Search Terminal Help [email protected]:~/Desktop/personal/python$ python timediff.py Please enter the first time: 0900 Please enter the second time: 1730 Difference between the two times: 8 hours and 30 minutes. [email protected]:~/Desktop/personal/python$ python timediff.py Please enter the first time: 1730 Please enter the second time: 0900 Difference between the two times: 15 hours and 30 minutes. [email protected]:~/Desktop/personal/python$


Similar Solved Questions

1 answers
A vertical straight wire carrying an upward 26 A current exerts an attractive force per unit...
A vertical straight wire carrying an upward 26 A current exerts an attractive force per unit length of 9.0*10^-4 N/m on a second parallel wire 9.0 cm away. What current (magnitude) flows in the second wire?...
1 answers
Develop a lesson plan on a topic of your choice that would be taught in a...
Develop a lesson plan on a topic of your choice that would be taught in a prelicensure nursing program (e.g. infection control, oxygenation, or a fundamental skill) Develop 3 objectives for the lesson plan using the cognitive, affective, and psychomotor domains of learning (there should be one objec...
1 answers
Please reply back to this post & ask one question regarding this post: As a nurse,...
please reply back to this post & ask one question regarding this post: As a nurse, when you supervise Licensed Vocational Nurses (LVN) or Certified Nursing Assistants (CNA), our role as nurses must be to take into account patient safety, the competency of the staff members and the acuity of the ...
1 answers
7. Three tsp of an antacid = Fill in the medicine cup below. OH TM 2...
7. Three tsp of an antacid = Fill in the medicine cup below. OH TM 2 TBS 1 TBS - 1 TSP - - 12 TSP 8. The nurse administers 2 tsp of cough syrup to the patient. How many mL will the nurse administer? Fill in the medicine cup below. 30 mL 11111 15 ml - 10 ml - 5 ml...
1 answers
The following information applies to the questions dsplayed below/ Tony and Suhe punchased land costing $500.000...
The following information applies to the questions dsplayed below/ Tony and Suhe punchased land costing $500.000 for a new camp in January 2020 Now they need money 1o build the cebins, diing faclity a ropes course, ond an ouadoor swming pool Tony and Sue r checked weh Sument Benk to see feey When th...
1 answers
If the strs palced in sector b had grown on the TSY + streptomycin agar plate...
if the strs palced in sector b had grown on the TSY + streptomycin agar plate would you have been able to determine if transformation had taken place?...
1 answers
X2 + 2x – 15 Let f(x) #3 X - 3 if x = 3 Find...
x2 + 2x – 15 Let f(x) #3 X - 3 if x = 3 Find the value of k which makes f continuous at x = 3. k3 1 Select one: O a.3 O b.8 Oc. 2 O d. 79 O e.O Å...
1 answers
A saturated aqueous solution of calcium hydroxide has a pH of 12.25. What is the [Ca2"]...
A saturated aqueous solution of calcium hydroxide has a pH of 12.25. What is the [Ca2"] of such a solution? SHOW ALL WORK...
1 answers
C. For most inventions, the US Patent Office only requires a written description of your invention...
c. For most inventions, the US Patent Office only requires a written description of your invention that would allow others to understand how to make your invention. It does not require a working prototype. However, for an invention that claims to be a “perpetual motion machine" - something...
1 answers
Find the present value of the ordinary annuity. (Round your answer to the nearest cent.) Amount...
Find the present value of the ordinary annuity. (Round your answer to the nearest cent.) Amount of Deposit Frequency Rate Time $400 quarterly 11% 20 yr $...
1 answers
36. What is a difference between a traditional Section 401(k) and a Section 401(k) plan established...
36. What is a difference between a traditional Section 401(k) and a Section 401(k) plan established as part of a SIMPLE? A. The SIMPLE 401(k) may not include loan or hardship withdrawal provisions similar to the traditional Section 401(k). B. The SIMPLE 401(k) does not require a mandatory employer c...
1 answers
(14%) 6. Consider an FM modulator with output )-100 cos(2(1000)r+(0) The modulator operates with fa = 8 and has the input message signal The modulator is followed by a bandpass filter with a...
(14%) 6. Consider an FM modulator with output )-100 cos(2(1000)r+(0) The modulator operates with fa = 8 and has the input message signal The modulator is followed by a bandpass filter with a a bandwidth of 56HZ, as shown in the following figure. Determine the power ratio and the power at the fiter o...
1 answers
Answer the following questions on a separate sheet of paper. Show your work. Calculate the theoretical...
Answer the following questions on a separate sheet of paper. Show your work. Calculate the theoretical analysis values for: a. 1,1-diiodo-2,2-dimethylpropane b. 1. 2C3 NHCH(CH3)2 CO2CH(CH3)2...
1 answers
Learning Goal: To learn how to write ionic formulas. Part A Here are some things to...
Learning Goal: To learn how to write ionic formulas. Part A Here are some things to remember when dealing with ionic compounds: What is the formula for nickel(III) oxide? Express your answer as a chemical formula. View Available Hint(s) • By convention, the cation is named first and the anion i...
1 answers
14 J. Morgan of SparkPlug Inc. has been approached to take over a production facility from...
14 J. Morgan of SparkPlug Inc. has been approached to take over a production facility from B.R. Machine Company. The acquisition will cost $1,900,000, and the after-tax net cash inflow will be $306,000 per year for 12 years. SparkPlug currently uses 9% for its after-tax cost of capital. Tom Morgan, ...
1 answers
Artan drug can be used to reduce the acid produced by the body and heal damage...
Artan drug can be used to reduce the acid produced by the body and heal damage to the esophagus due to acid reflux. The manufacturer of the drug claims that more than 92% of patients taking the drug are healed within 8 weeks. In clinical trials, 214 of 231 patients suffering from acid reflux disease...
1 answers
A diatomic gas is at a pressure of 100 kPa, 500 cm3 and 20 ° C...
A diatomic gas is at a pressure of 100 kPa, 500 cm3 and 20 ° C (point A), it is carried through the following processes. • Compresses adiabatically with a compression ratio equal to 6 (ie VA / VB = 6). • Then it is heated at constant volume until reaching 1000 K. • Then it expands...

-- 0.043464--