python program to find average of numbers in a list
In this python programming tutorial, we are going to learn
-
python program to find average of numbers in a list
python program to find average of numbers in a list
The python program to calculate average of numbers in a list is as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
marks = list(map(int,input("Enter marks: ").strip().split()))
summation = sum(marks)
count = len(marks)
average = summation/count
print("The average is:",average)
The output of python program to calculate average of numbers in a list is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter marks: 10 20 30 40
The average is: 25.0
Few important tips about the program
1. First of all, we ask the user to enter the marks. The .strip() method removes blank spaces in the front and back of the long string. The .split() method break the numbers spacewise. Then the map() functions maps each of the numbers to type cast them from string to int and then with all such numbers we get a list.
2. The sum() function returns the sum of all the elements which are present within a list.
3, The len() function returns the length of the list in Python.
python program to calculate average of numbers in a list snapshot:
This wraps our session on python program to find average of numbers in a list.
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :
Published Date :
Jun 21,2022