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 :: difference between 2 timestamps pandas 
Python :: python get dictionary keys 
Python :: index of max in tensor 
Python :: send message if user is banned discord.py 
Python :: ternary operator python 
Python :: print str and float python 
Python :: select specific rows from dataframe in python 
Python :: pandas dataframe from tsv 
Python :: save and load a machine learning model using Pickle 
Python :: python close database connection 
Python :: changing axis labels matplotlib 
Python :: python regex get string before character 
Python :: numpy datetime64 get day 
Python :: isprime python 
Python :: calcutalte average python 
Python :: save plotly figure as png python 
Python :: pandas shift column down 
Python :: python ssh connection 
Python :: pandas difference between dates 
Python :: sample data frame in python 
Python :: python argparse type date 
Python :: with open python 
Python :: Renaming an index in pandas data frame 
Python :: python render_template 
Python :: set form field disabled django 
Python :: make blinking text python 
Python :: print index of tuple python 
Python :: how to change turtle shape in python 
Python :: conda env 
Python :: filter function in pandas stack overflow 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =