This is what I have, but it tells me that float, or int is not subscriptable.

I am open to other methods of performing the task, but the input must be stored in a list, and then the necessary values displayed (maximum, minimum, average, and total)

def collect_numbers():
    numbers = [input("Enter any whole number: ") for i in range(10)]
    numbers2 = map(float, numbers)
    print("The smallest number is: ", min(data[numbers2] for data in numbers2))
    print("The largest number is: " , max(data[numbers2] for data in numbers2))
    print("The total of the numbers is: ", sum(data[numbers2] for data in numbers2))
    print("The average of the numbers is: ", (sum(data[numbers] for data in numbers2)/2))

collect_numbers()

EDIT: After reading some other things online, combined with answers here, I swapped to using this:

def collect_numbers():

    numbers = [input("Enter any whole number: ") for i in range(10)]
    print("The smallest number is: ", min(numbers, key=float))
    print("The largest number is: " , max(numbers, key=float))
    print("The total of the numbers is: ", sum(int(i) for i in numbers))
    print("The average of the numbers is: ", sum(int(i) for i in numbers)/10)

collect_numbers()

With the numbers2 = map(int, numbers) method, I was getting errors when trying to run ANY type of sum, max, min or anything on numbers2. Gave me map errors, non subscriptible, empty keyword arguments, etc.

But it works now, thanks for the swift responses!

2

There are 2 answers

2
kevinsa5 On

Just pass the functions the list, not a comprehension of the list (which I can't make sense of anyways):

min(numbers2)
max(numbers2)

etc.

Also, as corn3lius pointed out correctly, dividing by two only works for two numbers. You should divide by the length of the list (using the len() function).

0
thefourtheye On
  1. You don't need numbers2 at all.

    numbers = [float(input("Enter any whole number: ")) for i in range(10)]
    
  2. Minimum value of a list can be found using min function like this

    min(numbers)
    
  3. Maximum value of a list can be found using max function like this

    max(numbers)
    
  4. Sum of values of a list can be found using sum function like this

    sum(numbers)
    
  5. Average of a list can be found using sum and len

    sum(numbers)/len(numbers)