Quick question.....

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Narsil

    Quick question.....

    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
  • Irmen de Jong

    #2
    Re: Quick question.....

    Narsil wrote:[color=blue]
    > 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?[/color]

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


    --Irmen

    Comment

    Working...