473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Function For Average Of A List Helppppp!!

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 7442
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
  1. 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
Laharl
849 Expert 512MB
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
Curtis Rutland
3,256 Expert 2GB
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
bvdet
2,851 Expert Mod 2GB
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
boxfish
469 Expert 256MB
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
Curtis Rutland
3,256 Expert 2GB
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

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Karl Ebener | last post by:
Hi! A newbie question: How can I check, whether a key has been pressed and take that input to perform some action? I don't want to wait for that input (=> no Enter needed) and the input should...
15
by: Daniel Rudy | last post by:
Hello, Consider the following code: /* resolve_hostname this resolves the hostname into an ip address. */ static void resolve_hostname(char result, const char hostname, const char server) {
2
by: jeremito | last post by:
I have created a class that inherits from the list object. I want to override the append function to allow my class to append several copies at the same time with one function call. I want to do...
1
by: vrush | last post by:
What are Methods of hash function?
9
by: Mike | last post by:
While trying to write a recursive function involving lists, I came across some (to me) odd behavior which I don't quite understand. Here's a trivial function showing the problem. for itm in l:...
3
by: iu2 | last post by:
Hi all, I find myselft wondering about the recommended way to pass strings to functions: int func(string s); or int func(const char *s);
5
RMWChaos
by: RMWChaos | last post by:
I am working on a script to create and remove DOM elements, and I want to make it as efficient as possible (no redundancies). Because DOM elements each have their own set of attributes, the function...
13
by: sedaw | last post by:
need to write function swap(*list,char X , char Y) that swap beteein items in liked list ; supose list: A ->B->C->D->NULL swap(list,A,B) result: list : B->A->C->D->NULL
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.