Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

average value of list elements in python

# Example to find average of list
number_list = [45, 34, 10, 36, 12, 6, 80]
avg = sum(number_list)/len(number_list)
print("The average is ", round(avg,2))
Comment

find average of list python

list = [15, 18, 2, 36, 12, 78, 5, 6, 9]

# for older versions of python
average_method_one = sum(list) / len(list) 
# for python 2 convert len to a float to get float division
average_method_two = sum(list) / float(len(list))

# round answers using round() or ceil()
print(average_method_one)
print(average_method_two)
Comment

python get average of list


#python3

def average(list): 
    result = sum(list) / len(list) 
    return result 

list = [68,68,71,71,71,75,71,78,91,98,75,71,84]
print(average(list))
Comment

python find the average of a list

numbers = [3, 18, 2, 1, 70, 12, 36, 12, 78, 5, 6, 9]

import statistics

print(statistics.mean(numbers))
Comment

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

n=int(input("Enter the number of elements to be inserted: "))
a=[]
for i in range(0,n):
    elem=int(input("Enter element: "))
    a.append(elem)
avg=sum(a)/n
print("Average of elements in the list",round(avg,2))
Comment

PREVIOUS NEXT
Code Example
Python :: tree in python 
Python :: generate coordinates python 
Python :: python regex (d)(?=d1) 
Python :: python catch print 
Python :: hexdigest python 
Python :: operator overloading python 
Python :: django reverse vs reverse_lazy 
Python :: connect and disconnect event on socketio python 
Python :: django make new application folder 
Python :: string slice python 
Python :: add item to list python 
Python :: pytest fixture 
Python :: mean squared error in machine learning formula 
Python :: matplotlib window size 
Python :: os module in python 
Python :: determine how 2 string si equal py 
Python :: python modulo 
Python :: class method in python 
Python :: what is serializer in django 
Python :: if loop python 
Python :: how to define a dictionary in python 
Python :: single line return python 
Python :: drop columns pandas dataframe 
Python :: cast as float python 
Python :: Syntax of Python Frozenset 
Python :: python and pdf 
Python :: python image heatmap 
Python :: python nested object to dict 
Python :: django filter values with e and operator 
Python :: oops python self and making an object of a class and calling function 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =