455,587 Members | 1,688 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,587 IT Pros & Developers. It's quick & easy.

# Function For Average Of A List Helppppp!!

 P: 2 hello im very new in python and i want to write a function that will return the sum of all the integer in a list how do i do that? someone please help me thank you Oct 27 '08 #1
6 Replies

 P: 2 hi im a beginner in python and im trying to write a function that calculates the average of a list of integers for ex: Expand|Select|Wrap|Line Numbers L = [1,2,3,4,5] i want to return 1+2+3+4+5 which will give me 15 can anyone help me pleaseee?? Oct 27 '08 #2

 Expert 100+ P: 849 Where are you running into trouble? We're not going to write your code for you, but we will help with specific questions about code you've written yourself. Oct 27 '08 #3

 Expert 2.5K+ P: 3,256 Look into loops. This is very basic stuff, and you have to show some initiative if you want any help. I'd have to guess you are a student and this is homework, and we have strict policies on how we can deal with homework questions. Also, what you are asking for is a sum, not an average. Oct 27 '08 #4

 Expert Mod 2.5K+ P: 2,851 Python builtin function sum() will return the sum of the numbers in a list. The average is then calculated by dividing the sum by the length of the list. Hint: Python builtin function len() will be useful. Oct 27 '08 #5

 Expert 100+ P: 469 The function should take the list as an argument. You should make a variable to store the total number in. You should loop through the list with a for loop. For each number, add it to the total number. Return the total number. I hope this gives you some idea of what to do. Good luck. P.S. This doesn't seem to have much to do with the original thread. I am hoping a nice moderator will come by and give this its own thread. Thank you, moderators. Oct 27 '08 #6

 Expert 2.5K+ P: 3,256 Please don't post your questions in other threads. That is called thread hijacking and is not allowed. I have split out your posts and merged them with this thread. MODERATOR Oct 27 '08 #7