When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers.

Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, adjust each integer in the list by subtracting the smallest value from all the integers.

Ex: If the input is

5
30
50
10
70
65
Then the output is:

20
40
0
60
55
The 5 indicates that there are five integers in the list, namely 30, 50, 10, 70, and 65. The smallest value in the list is 10, so the program subtracts 10 from all integers in the list.

Respuesta :

Answer:

my_array = []

minimum_value=0;

list_length = int(input("List size : "))

for i in range(0, list_length):

   input_val = int(input())

   if i==0:

       minimum_value=input_val

   if input_val < minimum_value:

       minimum_value=input_val

   my_array.append(input_val)

print(my_array)

print(minimum_value)

for i in range(0, list_length):

   my_array[i]=my_array[i]-minimum_value

print(my_array)

Explanation:

  1. Get list size from user
  2. While getting input set initial value as minimum
  3. For every input check if current input value is less than minimum, set current minimum to current value input.
  4. Print array
  5. Loop through list again to subtract lowest value from array.
  6. Subtract each value from a value in array and update current value.
  7. Print array