Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I take the average (mean) of inputted numbers in Python?

I would like to take create a code that takes an input of numbers, and then takes the average (mean) of these numbers. So far, I have this:

from statistics import mean

numbers=int(input("Enter some numbers. Seperate each number by a space: ") 
average=mean(grades)
print(average)

Running this code gives me an error stating "invalid literal for int() with base 10: ‘ 12 13 14 15 16 17 17’". I have tried to convert the input into a list, but this also failed; I don’t know what else to do or try.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

numbers=[int(x) for x in input("Enter some numbers. Seperate each 
number by a space: ").split()]
print(numbers)
average=mean(numbers)
print(average)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading