Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.