![]() |
Coding this function
Does anyone know how to code this function? :)
An average function, that when the function is coded, it returns the average of the integers typed in a list: for example: mean(listofinteger) >>> mean([4,5,6]) 5 >>> mean([7,8,9]) 8 etc |
Sounds like homework. :rolleyes:
|
Yea. =(
|
Imagine how you would discover the mean if you were doing it mentally and write Python code to do the same thing. If it doesn't work for you, show your code and ask for help. Incidentally, the mean that you indicate that you want is not the average.
|
Quote:
|
You are correct, of course, too much turkey and Texas Hold 'Em fried my brain again.
|
Seems like no one wants to answer your question. So will be the first. =) Yes, I know how to code a function that does that.
Since you show the ability to find the average of numbers yourself, I assume that the previous people that replied were correct in saying that this is a homework problem. Here are some clues if you are still stuck: 1. The average, as you probably know, is the sum of all the elements of the list divided by the length of the list. 2. A way of accessing the elements in the list is by using a 'for' loop. 3. The len() method will return the length of the list. |
It might be "cheating", but there is the "sum" function.
:
>>> sum([4,5,6]) |
It might be "cheating", but there is the "len" function.
:
>>> len([7,8,9]) |
Quote:
|
| All times are GMT -5. The time now is 8:22 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC