+ 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 .
15 Respuestas
+ 5
You completed 2 Python courses on sololearn. If you don't remember how a for-loop works, review the lessons
+ 3
You just need to use sum(list) function
+ 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
+ 2
code for your loop
sum=0
for i in list:
sum+=i
you should review for loops lesson
+ 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
+ 1
👉 please read my previous comment again 👈
+ 1
List_toatl = 0
for i in list(range(10)):
List_total += i
print(List_total)
This should output 45
0
Yes but sum add all numbers at same time
0
So I need a loop who add two numbers , then add one more then one more.
0
Yes it will work too
0
Lisa can you show me
0
Thanks friends thanks a lot
0
Stalowy , yes bro I need review for loop .
0
You need a while loop for the Feedback from your c code
0
What about sum(list)?