![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2006
Posts: 2
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Sounds like homework.
![]() |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2006
Posts: 2
Rep Power: 0
![]() |
Yea. =(
|
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
|
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You are correct, of course, too much turkey and Texas Hold 'Em fried my brain again.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#7 |
|
Newbie
|
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. |
|
|
|
|
|
#8 |
|
Programming Guru
![]() |
It might be "cheating", but there is the "sum" function.
>>> sum([4,5,6]) 15 >>> sum([7,8,9]) 24 |
|
|
|
|
|
#9 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
It might be "cheating", but there is the "len" function.
>>> len([7,8,9]) 3
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#10 | |
|
Newbie
Join Date: Aug 2006
Posts: 13
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Combining languages | titaniumdecoy | Other Programming Languages | 12 | Jul 13th, 2006 2:03 PM |
| Compiling Maverik 6.2 (from C) | megamind5005 | C | 16 | May 3rd, 2006 5:41 PM |
| libraries | matko | C | 1 | Jan 22nd, 2006 2:12 PM |
| Jackpot game | zorin | Visual Basic | 3 | Jun 10th, 2005 1:19 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 4:12 PM |