Introduction to Python

min max abs

Python provides a big list of built-in functions that make performing many operations way easier.
print() and input() are great examples of such built-in functions. When dealing with computations, in many cases it’s required to compute min or max values among several values. To help with those operations python provides built-in functions min(), max(), and abs() to compute the minimum, maximum, and the absolute value correspondingly.
# max() examples
print(max(10, 17, 12))          # 17
a = max(0, -8)                  # 0

# min() examples
print(min(11, 10, 2, -7, 0))    # -7
print(min(3, a, -1))            # -1

# abs() examples
print(abs(-10))                 # 10
print(abs(10))                  # 10
x = -2
x = abs(x)
print(x)                        # 2
Notice that abs() takes only a single value and computes the absolute value for only 1 item, while min() and max() operate with an arbitrary number of values.
Try providing min or max a single value. What will happen? Why?


Given 4 floating-point numbers in the input, compute their minimum and maximum and print the values in the output side by side. The next 4 lines should contain the absolute values for all the inputted numbers.
0 3.3 4 -2.3
-2.3 4 0 3.3 4 2.3


Time limit: 1 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue