10.7k views
0 votes
6.36 lab: subtracting list elements from max - functions 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. for this program, adjust the values by subtracting each value from the maximum. the input begins with an integer indicating the number of integers that follow. assume that the list will always contain between 1 and 20 integers. ex: if the input is:

User Milan Tenk
by
8.2k points

2 Answers

0 votes

Final answer:

To adjust the values by subtracting each value from the maximum, follow these steps: read input, find maximum, subtract each value from the maximum, and print adjusted values.

Step-by-step explanation:

To adjust the values by subtracting each value from the maximum, you need to follow these steps:

  1. Read the input to determine the number of integers in the list.
  2. Declare a variable to store the maximum value, and initially set it to the first integer in the list.
  3. Iterate through the remaining integers in the list. If any integer is greater than the current maximum, update the maximum value.
  4. Iterate through the list again and subtract each integer from the maximum value.
  5. Print the adjusted values.

For example, if the input is [4, 7, 2, 9, 5], the maximum value is 9. Subtracting each integer from 9 would result in the adjusted values: [5, 2, 7, 0, 4].

User Nyasia
by
8.5k points
4 votes

This program takes the number of integers as input, followed by the list of integers, and then it adjusts the values by subtracting each value from the maximum.

def adjust_values(lst):

# Find the maximum value in the list

max_value = max(lst)

# Adjust each value by subtracting it from the maximum

adjusted_values = [max_value - value for value in lst]

return adjusted_values

def main():

# Input: Number of integers

num_integers = int(input())

# Input: List of integers

integer_list = [int(input()) for _ in range(num_integers)]

# Adjust values and print the result

result = adjust_values(integer_list)

for value in result:

print(value)

if __name__ == "__main__":

main()

User Joshua Wilson
by
9.2k points