Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to average in python with loop

list = input('Input a list of numbers separated by comma then space:
 ')
try:
    list = list.split(', ')
    sum = 0
    
    for number in list:
        sum = int(number) + sum

    avg = sum / len(list)
    print('The average of the numbers you entered is: ', avg)
except ValueError:
    print('Please enter a list of number separated by a comma and space only')
Comment

python for loop: mean/average

def mean(numbers):
    total = 0
    for number in numbers:
        total += number
    return total / len(numbers)
Comment

PREVIOUS NEXT
Code Example
Python :: python get all methods of object 
Python :: how to add and subtract days datetime python 
Python :: python swap 0 into 1 and vice versa 
Python :: python change base function 
Python :: replace multiple spaces with single space python 
Python :: dict to array of string python 
Python :: sort json python 
Python :: get variance of list python 
Python :: django not saving images forms 
Python :: How to make an simple python client 
Python :: np range data 
Python :: argparse example python pyimagesearch 
Python :: python make api request 
Python :: python for with iterator index 
Python :: python if else short version 
Python :: pandas read csv as strings 
Python :: python poner en mayusculas 
Python :: python split list of tuples in two lists 
Python :: show aruco marker axis opencv python 
Python :: md5 hash python 
Python :: python if else variable assignment 
Python :: python sftp put file 
Python :: sklearn accuracy 
Python :: can you print to multiple output files python 
Python :: python copy all files in a folder to nother folder 
Python :: pygame window 
Python :: Consider using python 3 style super without arguments 
Python :: max of a dict 
Python :: how to run a function in interval in python 
Python :: gspread send dataframe to sheet 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =