Absolute Difference
Programming Basics · Python
TASK
Problem
Given `a` and `b`, print the absolute difference.
EXAMPLE
Example
3 10
7
LIMITS
Constraints
All integer inputs have absolute value at most 10^9; any additional relationships between them are stated directly in the task.
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. `abs()` returns the absolute value of a number. The `-` operator subtracts one number from another. `print()` displays the program result. Print only what the problem statement requires.
**Connection to this task.** The `abs(x)` function returns the absolute value: the non-negative distance from `x` to zero regardless of the original sign. The expression `abs(a - b)` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['Use `abs(a - b)`.']
ANSWER
Solution
+
a, b = map(int, input().split()) result = abs(a - b) print(result)