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”.
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')
Comments
Leave a comment