Python Program To Calculate Average of Numbers | RRTutors
Learn how to calculate the average of numbers in a list using Python. Step-by-step guide to input, sum, and divide numbers at rrtutors.com. Check it out!
In this Python example we will learn how to calculate Average of Numbers from given list.
This Example will Give the Solution by below points
- Take the input for number of elements we need to calculate average
- Then Loop the function to take the input values based on above given number
- Calculate the Sum of total numbers given by the loop
- Divide the Total sum by total number of elements
Program to calculate average of numbers
n=int(input("Enter the number of elements to be inserted: ")) |
Explanation:
- First user will enter the number, how many numbers he wants to calculate. The value will be stored in 'n'
- Now we are creating a loop with start index 0 and range up to given number 'n'
- Now each iteration of loop the value will be taking from input() method and stored it in 'take' variable
- The above loop will be take inputs and store into list 'numbers'
- Then calculating the sum of given elements by 'sum()' method
- Finally we are calculating the average of all numbers by avg=sum(numbers)/n
Output:
Enter the number of elements to be inserted: 10 |
Read How to concatenate Strings in Python
Conclusion: We can calculate average of any numbers by above python program to calculate average of numbers in the given list.