Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 23rd, 2006, 3:38 PM   #1
Macdonalds
Newbie
 
Join Date: Nov 2006
Posts: 2
Rep Power: 0 Macdonalds is on a distinguished road
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
Macdonalds is offline   Reply With Quote
Old Nov 23rd, 2006, 3:46 PM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Sounds like homework.
Arevos is offline   Reply With Quote
Old Nov 23rd, 2006, 3:47 PM   #3
Macdonalds
Newbie
 
Join Date: Nov 2006
Posts: 2
Rep Power: 0 Macdonalds is on a distinguished road
Yea. =(
Macdonalds is offline   Reply With Quote
Old Nov 23rd, 2006, 4:40 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Nov 23rd, 2006, 5:49 PM   #5
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by DaWei View Post
Incidentally, the mean that you indicate that you want is not the average.
Seems like the average to me.
Arevos is offline   Reply With Quote
Old Nov 23rd, 2006, 7:08 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Nov 23rd, 2006, 7:34 PM   #7
purpleorange
Newbie
 
purpleorange's Avatar
 
Join Date: Oct 2006
Location: Oh gosh, where I live. This is all so sudden.
Posts: 7
Rep Power: 0 purpleorange is on a distinguished road
Send a message via AIM to purpleorange
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.
purpleorange is offline   Reply With Quote
Old Nov 23rd, 2006, 8:32 PM   #8
Sane
Banned
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,101
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
It might be "cheating", but there is the "sum" function.

>>> sum([4,5,6])
15
>>> sum([7,8,9])
24
Sane is offline   Reply With Quote
Old Nov 26th, 2006, 1:38 PM   #9
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
It might be "cheating", but there is the "len" function.
>>> len([7,8,9])
3
Homework? I can't believe that there are actually schools progressive enough to teach Python. I thought most of those institutions of higher learning were stuck with Java.
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Nov 27th, 2006, 3:19 AM   #10
public2
Newbie
 
Join Date: Aug 2006
Posts: 13
Rep Power: 0 public2 is on a distinguished road
Quote:
Originally Posted by Dietrich View Post
It might be "cheating", but there is the "len" function.
>>> len([7,8,9])
3
Homework? I can't believe that there are actually schools progressive enough to teach Python. I thought most of those institutions of higher learning were stuck with Java.
We're learning Python AND Java, and the integration between them, but in this first semester, we just learned Python. Baby steps :-)
public2 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining languages titaniumdecoy Other Programming Languages 12 Jul 13th, 2006 3:03 PM
Compiling Maverik 6.2 (from C) megamind5005 C 16 May 3rd, 2006 6:41 PM
libraries matko C 1 Jan 22nd, 2006 3:12 PM
Jackpot game zorin Visual Basic 3 Jun 10th, 2005 2:19 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 5:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:46 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC