Find elements

Python program to find Average of numbers in a list

Python program to find Average of numbers in a list

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

Calculate average in an integer number list

In this programs, we can see step by step procedure for completion of the program.

  • Define the sum variable and initialize as zero
  • Create a number list in Python language
  • use a for loop for calculating the sum
  • then, calculates the average of the list elements
  • Which Displays sum and average on the screen

 

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

Calculate average in a decimal number list

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

Calculate average in an integer number list -takes input from the user

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.

  • Define the sum variable and initialize as zero
  • Create an empty list in Python language
  • Takes input from the user for the number of elements in the list
  • Use a for loop to store element in the list and calculate the sum
  • Then, calculates the average of the list elements
  • Finally, Which is Displayed sum and average on the screen
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

Calculate average in a decimal  number list -takes input from the user

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

operator in Python

Python program to find largest number among three numbers
Python program to find largest and smallest elements in a list
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago