Advertisement
aneliabogeva

On time for Exam V2

May 8th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import math
  2.  
  3. test_hour = int(input())
  4. test_minutes = int(input())
  5. arrival_hour = int(input())
  6. arrival_minutes = int(input())
  7.  
  8. test_time = int(test_hour) * 60 + int(test_minutes) # convert test time in to minutes
  9. arrival_time = int(arrival_hour) * 60 + int(arrival_minutes) # convert arrival time in to minutes
  10.  
  11. time_difference = test_time - arrival_time # compare test time and arrival time
  12. time = abs(time_difference)
  13.  
  14. if time_difference < 0: # student is late
  15. print("Late")
  16. if 0 <= time < 60: # student is late within 60 minutes
  17. print(time, "minutes after the start")
  18. else: # student is late more than 60 minutes
  19. hours_late = abs(test_hour - arrival_hour)
  20. minutes_late = abs(test_minutes - arrival_minutes)
  21. if minutes_late < 10: # if student is late up to 10 minutes
  22. print(f"{hours_late}:0{minutes_late} hours after the start")
  23. else:
  24. print(f"{hours_late}:{minutes_late} hours after the start")
  25. elif time_difference == 0: # if student is exactly on time
  26. print("On time")
  27. elif 0 < time_difference <= 30: # if student is earlier within 30 minutes
  28. print("On time")
  29. print(time, "minutes before the start")
  30. else: # if student is earlier more than 30 minutes
  31. if 30 < time < 60:
  32. print("Early")
  33. print(time, "minutes before the start")
  34. else:
  35. hours_before = math.ceil(test_time - arrival_time)//60
  36. minutes_before = (test_time - arrival_time) % 60
  37. if minutes_before < 10:
  38. print("Early")
  39. print(f"{hours_before}:0{minutes_before} hours before the start")
  40. else:
  41. print("Early")
  42. print(f"{hours_before}:{minutes_before} hours before the start")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement