Find average of a list in python?
Answers
Prerequisites: sum() function, len() function, round() function, reduce(), lambda, and mean().
Given a list of numbers, the task is to find average of that list. Average is the sum of elements divided by the number of elements.
Examples:
Input : [4, 5, 1, 2, 9, 7, 10, 8]
Output : Average of the list = 5.75
Explanation:
Sum of the elements is 4+5+1+2+9+7+10+8 = 46
and total number of elements is 8.
So average is 46 / 8 = 5.75
Input : [15, 9, 55, 41, 35, 20, 62, 49]
Output : Average of the list = 35.75
Explanation:
Sum of the elements is 15+9+55+41+35+20+62+49 = 286
and total number of elements is 8.
So average is 46 / 8 = 35.75
hope you like it.....
please mark it as brainlist
Average is basically the division of the sum of the numbers by the total number of numbers.
For a list, to add up all the numbers, we use sum() and to find the total number of number in a list, we used the len() command. This calculates the length of the list.
So, to find the average of a list, it's simple.
Let's say out list's name is my_list.
my_list = [1,2,3,4,5]
average = sum(my_list)/len(my_list)
The output would be: 3.0
Hope it helps!