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 :: random string generate python of 2.7 
Python :: Create list with numbers between 2 values by 
Python :: input and ouput array in python 
Python :: initialize dictionary to zero in python 
Python :: how to get dummies in a dataframe pandas 
Python :: python file.write is not writing whole line 
Python :: odoo scaffold 
Python :: get just filename without extension from the path python 
Python :: python count empty lines in text file 
Python :: split string and convert to int python 
Python :: python add up values in list 
Python :: make screen shot of specific part of screen python 
Python :: python find item in list 
Python :: make tkinter label and input 
Python :: render template in django 
Python :: how to encode hexadecimal python 
Python :: python read lines 
Python :: get current data with python 
Python :: finding the rows in a dataframe where column contains any of these values python 
Python :: if __name__ == 
Python :: error command errored out with exit status 1 face_recognition 
Python :: django app 
Python :: remove all odd row pandas 
Python :: python telethon 
Python :: remove hyperlink from text python 
Python :: binary to decimal python 
Python :: how to append leading zeros in python 
Python :: how to count backwards in for loop python 
Python :: user input of int type in python 
Python :: django set random password 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =