0

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.

4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by richieking
Featured Replies
  • This should help,and try to post some code next time. [CODE]>>> from __future__ import division >>> my_list = [1,2,3,4] >>> avg = sum(my_list)/len(my_list) >>> avg 2.5 >>> [/CODE] Read More

  • Well you can try this. [CODE] 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 [/CODE] hope it helps ;) Read More

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

1

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
>>>
0

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 by woooee: n/a

1

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 by richieking: n/a

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.