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.
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...
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)
{
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...
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:...
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...
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
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...
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...
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,...
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...
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,...
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...
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...
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...
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...