Time Difference
Programming Basics · Python
TASK
Problem
Given two times in one day `h1 m1 h2 m2`, with the second not earlier, print the difference in minutes.
EXAMPLE
Example
10 15 12 0
105
LIMITS
Constraints
0≤h≤23; 0≤m≤59; second ≥ first
LEARN
Theory for this problem
+
`input()` reads data entered by the user. The result of `input()` is initially a string. `split()` separates one input line into individual values using spaces. `map()` applies the specified conversion to each input value. The `+` operator adds numbers. The `-` operator subtracts one number from another. The `*` operator multiplies numbers. `print()` displays the program result. Print only what the problem statement requires.
**Connection to this task.** The `*` operator multiplies numeric values. In formulas it naturally models repeated contribution, such as price × quantity, speed × time, or side × side. The expression `t2 - t1` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['Convert both times to minutes from midnight.']
ANSWER
Solution
+
h1, m1, h2, m2 = map(int, input().split()) t1 = h1 * 60 + m1 t2 = h2 * 60 + m2 print(t2 - t1)