Min-max scaling

Scale a feature to the range 0 to 1 with min-max scaling: x′ = (x − min) / (max − min).

Input

One line of 1 to 1000 numbers.

Output

The scaled values in the same order, each with 3 decimal places, separated by spaces. If all the values are equal, every scaled value is 0.000.

Examples

Example 1 · Input
650 1200 900 2400 1500
Expected output
0.000 0.314 0.143 1.000 0.486
Example 2 · Input
-5 0 5
Expected output
0.000 0.500 1.000

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

x′ = (x − min) / (max − min).

Hint 2

If every value is the same, max − min is 0: print 0.000 for each.

Hint 3

f"{v:.3f}" for each value, joined with spaces.

Solution

Show one correct solution (try it yourself first)
xs = [float(x) for x in input().split()]
lo, hi = min(xs), max(xs)
if hi == lo:
    print(" ".join("0.000" for _ in xs))
else:
    print(" ".join(f"{(x - lo) / (hi - lo):.3f}" for x in xs))

Lesson: Data, statistics and features →