Middle Number
Programming Basics · Python
TASK
Problem
Given three distinct integers, print the middle value.
EXAMPLE
Example
9 2 5
5
LIMITS
Constraints
a, b, c are distinct
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. Comparison operators `==`, `!=`, `<`, `>`, `<=`, `>=` compare values and produce `True` or `False`. `or` requires at least one condition to be true. `if` checks a condition and runs its block when the condition is true. `else` runs when the corresponding `if` condition is false. `print()` displays the program result. Print only what the problem statement requires.
**Connection to this task.** An `if` statement chooses a program branch from a Boolean condition. Comparisons produce `True` or `False`, and `elif` lets you test several mutually exclusive cases in order. The expression `a` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['`a` is middle if it lies between `b` and `c` in either order.']
ANSWER
Solution
+
a, b, c = map(int, input().split())
if b < a < c or c < a < b:
print(a)
elif a < b < c or c < b < a:
print(b)
else:
print(c)