PYTHON:

I have no idea where to start this, but i need to write code that takes a list of real numbers as input and returns the average of the numbers in the list.

any input as to how i would go about starting this code would be much appreciated.

This should help,and try to post some code next time.

>>> from __future__ import division
>>> my_list = [1,2,3,4]
>>> avg = sum(my_list)/len(my_list)
>>> avg
2.5
>>>

takes a list of real numbers as input

And how are the numbers input; from a file, or via the keyboard. Whichever it is, that is where you want to start. Read the input from a file or the keyboard into a list, and post that code for further help.

Well you can try this.

from __future__ import division

my_list=list(raw_input("enter number: ")) # you take the input from the user
avg=sum([int(x) for x in my_list])/len(my_list) 
print(avg)

#out Put
enter number: 1234
     2.5

hope it helps ;)

Well you can try this.

from __future__ import division

my_list=list(raw_input("enter number: ")) # you take the input from the user
avg=sum([int(x) for x in my_list])/len(my_list) 
print(avg)

#out Put
enter number: 1234
     2.5

hope it helps ;)

Brilliant! This is just what i needed

Thank you very much :cool:

thread closed

Please close the thread and upvote me if you think i deserve it. ;)
Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.