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 average of 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

average of a list in function with python

def lol(a):
	x = sum(a)/len(a)
	print(x)
lol([5,7,3,9,4])
Comment

PREVIOUS NEXT
Code Example
Python :: http client post python 
Python :: Chi-Squared test in python 
Python :: regular expression to remove space python 
Python :: python remove repeated elements from list 
Python :: search dictionary for value 
Python :: jupyter notebook for pdf generation 
Python :: pandas drop row from a list of value 
Python :: how to print answer 2 decimal places in python 3 
Python :: how to play video in colab 
Python :: python matplt 
Python :: user input python 
Python :: how to use static files in django 
Python :: python epoch to datetime 
Python :: python timestamp to yyyy-mm-dd 
Python :: discord py get all channels in guild 
Python :: clone website 
Python :: discord.py get channel id by channel name 
Python :: Python list of dictionaries search 
Python :: publisher python ros 
Python :: how to find if the numpy array contains negative values 
Python :: print pretty in python 
Python :: remove last element from list python 
Python :: python sort columns of pandas dataframe 
Python :: non-default argument follows default argument 
Python :: opencv python grayscale image to color 
Python :: back button django template 
Python :: python for loop one line 
Python :: get subscriber count with python 
Python :: python dataframe replace nan with 0 
Python :: difference between supervised and unsupervised learning 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =