+ 1

I have a list of int and I want to add all numbers one by one . But I can't. Please friends help me .

A list of int , and I want a loop who add (+) numbers one by one .

7th Jan 2022, 12:46 PM
🔰 Arit Dey 🔰
🔰 Arit Dey 🔰 - avatar
15 Answers
+ 5
You completed 2 Python courses on sololearn. If you don't remember how a for-loop works, review the lessons
7th Jan 2022, 12:54 PM
Lisa
Lisa - avatar
+ 3
You just need to use sum(list) function
7th Jan 2022, 12:48 PM
Bartek
+ 2
* create a variable that holds the sum and assign 0 to it, e.g. result + 0 * loop over the array, on each iteration add the current number to result There is a built-in function sum() that sums numbers in a list
7th Jan 2022, 12:49 PM
Lisa
Lisa - avatar
+ 2
code for your loop sum=0 for i in list: sum+=i you should review for loops lesson
7th Jan 2022, 12:54 PM
Bartek
+ 2
>>> my_list = [1, 2, 3, 4, 5] >>> sum(my_list) 15 >>> s = 0 >>> for i in my_list: . . . s += i # s = s + i >>> s 15
8th Jan 2022, 9:42 AM
Delta
Delta - avatar
+ 1
👉 please read my previous comment again 👈
7th Jan 2022, 12:52 PM
Lisa
Lisa - avatar
+ 1
List_toatl = 0 for i in list(range(10)): List_total += i print(List_total) This should output 45
8th Jan 2022, 11:22 AM
Nucleus Erumagborie
Nucleus Erumagborie - avatar
0
Yes but sum add all numbers at same time
7th Jan 2022, 12:50 PM
🔰 Arit Dey 🔰
🔰 Arit Dey 🔰 - avatar
0
So I need a loop who add two numbers , then add one more then one more.
7th Jan 2022, 12:51 PM
🔰 Arit Dey 🔰
🔰 Arit Dey 🔰 - avatar
0
Yes it will work too
7th Jan 2022, 12:52 PM
Bartek
0
Lisa can you show me
7th Jan 2022, 12:53 PM
🔰 Arit Dey 🔰
🔰 Arit Dey 🔰 - avatar
0
Thanks friends thanks a lot
7th Jan 2022, 12:55 PM
🔰 Arit Dey 🔰
🔰 Arit Dey 🔰 - avatar
0
Stalowy , yes bro I need review for loop .
7th Jan 2022, 12:57 PM
🔰 Arit Dey 🔰
🔰 Arit Dey 🔰 - avatar
0
You need a while loop for the Feedback from your c code
9th Jan 2022, 2:43 AM
Shubham Bhatia
Shubham Bhatia - avatar
0
What about sum(list)?
9th Jan 2022, 10:30 AM
Tjipke van der Heide
Tjipke van der Heide - avatar