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!
Just pass the functions the list, not a comprehension of the list (which I can't make sense of anyways):
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).