Answer to Question #292104 in Python for Maryam

Question #292104

Aleena’s sister who studies in UK coming to Pakistan over winter break. She wants to make a

program that easily calculates the difference between the time of arrival and departure of her

flight.

Write a program that takes in an input from the user for the time of arrival and time of departure

in military format. Using an if/else statement, find the difference in number of hours and minutes

between the two times. Keep in mind that the time of departure is later than the time of arrival

otherwise the program should give an error, “Incorrect Input”.


1
Expert's answer
2022-01-30T05:16:13-0500
arrival = int(input("Enter time of arrival: "))
h_arr = arrival // 100
m_arr = arrival % 100
if h_arr > 24 or m_arr > 59:
    print("Incorect Input")
    exit()

departue = int(input("Eter time of departure: "))
if arrival <= departue:
    print("Incorect Input")
    exit()

h_dep = departue // 100
m_dep = departue % 100
if h_dep > 24 or m_dep > 59:
    print("Incorect Input")
    exit()

h = h_arr - h_dep
m = m_arr - m_dep
if m < 0:
    m += 60
    h -= 1

print(f'The time difference between arival and departure is {h} hours and {m} minutes')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS