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 :: grid in pygame 
Python :: brownie from wei to ether 
Python :: python split range equally 
Python :: char to binary python 
Python :: python turtle line thickness 
Python :: python get current number of threads 
Python :: utf8 python encodage line 
Python :: python dns pip 
Python :: set icon title tkinter 
Python :: pandas drop zero values 
Python :: how to apply labelencoder on multiple columns at once 
Python :: csv to numpy array 
Python :: python append in specific position 
Python :: python datetime to string iso 8601 
Python :: get current time in python with strftime 
Python :: parse youtube video id from youtube link python 
Python :: tkinter boilerplate 
Python :: ImportError: No module named django.core.wsgi 
Python :: python install module from script 
Python :: python choose random sample from list 
Python :: Connecting Kaggle to Google Colab 
Python :: how to read pdf in python 
Python :: python querystring parse 
Python :: load saved model 
Python :: printable characters python 
Python :: fraction thesis 
Python :: dataframe to txt 
Python :: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. 
Python :: get text between two strings python 
Python :: sns seaborn set theme 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =