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
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.
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.
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.
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.
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.
Comment