In this tutorial, we will discuss a concept of Python program to find Average of numbers in a list.
This program uses to calculate the sum and average of the integer number in the list of Python language.
If the list of numbers given to find the average, the sum of the numbers divided by the number of elements of the list.
Program 1
In this programs, we can see step by step procedure for completion of the program.
sum=0 #find sum of list elements ListSum=[45,78,54,23,67]#crate a list in Python for num in ListSum: sum=sum+num;#calculate sum avg=sum/len(ListSum)#calculate average print("Sum of list elements is ",sum) print("Average of list elements is ",avg) #display result on the screen
When the above code is executed, it produces the following results
Sum of list elements is 267 Average of list elements is 53
Program 2
sum=0 #find sum of list elements ListSum=[45.45,78.23,58.54,96.23,45.67]#crate a list in Python for num in ListSum: sum=sum+num; #calculate sum avg=sum/len(ListSum) #calculate average print("Sum of list elements is ",sum) print("Average of list elements is ",avg) #display result on the screen
When the above code is executed, it produces the following results
Sum of list elements is 324.12 Average of list elements is 64.824
Program 3
This program takes input from the user one by one and calculates sum and average of the integer number in the list
In this programs, we can see step by step procedure for completion of the program.
sum=0 #find sum of list elements ListSum=[] #crate a empty list in Python #takes input for numbers in list num=int(input("how many numbers: ")) for n in range(num): numbers=int(input("Enter numbers: ")) sum=sum+numbers; avg=sum/num print("Sum of list elements is ",sum) print("Average of list elements is ",avg)
When the above code is executed, it produces the following results
how many numbers: 5 Enter numbers: 12 Enter numbers: 23 Enter numbers: 34 Enter numbers: 45 Enter numbers: 56 Sum of list elements is 170 Average of list elements is 34)
Program 4
This program takes input from the user one by one and calculates sum and average of the decimal number in the list
sum=0 #find sum of list elements ListSum=[]#crate a empty list in Python #takes input for numbers in list num=int(input("how many numbers: ")) for n in range(num): numbers=float(input("Enter numbers: ")) sum=sum+numbers; avg=sum/num print("Sum of list elements is ",sum) print("Average of list elements is ",avg)
When the above code is executed, it produces the following results
how many numbers: 6 Enter numbers: 12.34 Enter numbers: 23.45 Enter numbers: 34.56 Enter numbers: 45.67 Enter numbers: 56.78 Enter numbers: 67.89 ('Sum of list elements is ', 240.69) ('Average of list elements is ', 40.115)
Suggested for you
for loop in Python
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…