Skip to content

How to average in Python with loop?

list = input('Input a list of numbers separated by comma then space:\n ')
    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')
See also  Python code snippet - print How long it takes to run?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.