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.

Edited 6 Years Ago by woooee: n/a

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 ;)

Edited 6 Years Ago by richieking: n/a

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:

This question has already been answered. Start a new discussion instead.