Quick question.....

N

Narsil

I have a list, which consists of just numbers.

Is there a command that will allow me to total up these numbers and get an average?

Say for example, the list looks thus:

numberlist = [10, 2, 5, 7, 3, 46, 4, 5, 87, 5]

How would I get the total, and how would I get the average?

Thanks in advance

TomN
 
I

Irmen de Jong

Narsil said:
I have a list, which consists of just numbers.

Is there a command that will allow me to total up these numbers and get an average?

Say for example, the list looks thus:

numberlist = [10, 2, 5, 7, 3, 46, 4, 5, 87, 5]

How would I get the total, and how would I get the average?

You could have guessed?
>>> numberlist=[10, 2, 5, 7, 3, 46, 4, 5, 87, 5]
>>> print sum(numberlist) 174
>>> print sum(numberlist)/len(numberlist) # watch out, integer result 17
>>> print float(sum(numberlist))/len(numberlist) # force float result
17.4


--Irmen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,944
Members
47,491
Latest member
mohitk

Latest Threads

Top