Python Program to Calculate the Average of Numbers in a Given List

 Hey There,


In this blog, I have shown how to calculate average of numbers in a given list.Average can be calculated as :
                          Average = (Sum of all the numbers)/(Total numbers)


Here the given list is :  list = [1,2,3,4,5,6,7,8,9]


Sum can be calculated as :  sum_all = sum(list)


Total numbers can be calculated as :  length = len(list)


Now, Average will be :   avg = (sum_all/length)


Printing the Average as :    print("Average is : ",avg)


The above code can be written in a single line as :

                         print("Average of numbers is : ", sum(list)/len(list))


Output : 

Python Program to Calculate the Average of Numbers in a Given List



Video Tutorial:

Comments

Popular posts from this blog

Python Program to Swap First and Last Element of a Given List

Python Program to Put Even and Odd Elements of a List into Two Different Lists