Newbie help needed - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Newbie help needed

mobomofomobomofo Posts: 1Member
Hi,
Im new to python and am working through a book. Im stuck on an activity which asks me to write a script to find out the average from a list or tuple of user defined numbers. I cant get the program to find numbers in the list.

Thanks in advance

Comments

  • infidelinfidel Posts: 2,900Member
    : Hi,
    : Im new to python and am working through a book. Im stuck on an activity which asks me to write a script to find out the average from a list or tuple of user defined numbers. I cant get the program to find numbers in the list.

    Python's lists are very powerful. Assuming you have a list of numbers, you can iterate through them like this:

    [code]
    total = 0
    for n in numberlist:
    total += n
    [/code]

    The number of items in your list is:

    [code]len(numberlist)[/code]

    That should be everything you need to find the average of numbers in a list.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

Sign In or Register to comment.