0

for Loops for loops allow you to easily iterate through lists. Given a list of numbers, calculate their sum using a for loop.

help me out please! this is what ive tried x = [42, 8, 7, 1, 0, 124, 8897, 555, 3, 67, 99] sum = 0 for x in list : sum += 1 print(sum) i couldnt pass throught this one

4th Feb 2022, 6:16 PM
Vitoria Scheuermann
4 Answers
+ 4
sum+=x
4th Feb 2022, 6:20 PM
rodwynnejones
rodwynnejones - avatar
+ 2
Thank you very much!!
4th Feb 2022, 7:38 PM
Vitoria Scheuermann
+ 1
There is a built-in function in Python for this purpose. You can use just this code as I used: x = [42, 8, 7, 1, 0, 124, 8897, 555, 3, 67, 99] print(sum(x)) # the 'sum' is a built-in function in Python
4th Feb 2022, 9:51 PM
Behzad Soleimani Neysiani
Behzad Soleimani Neysiani - avatar
+ 1
Thank you Behzad Soleimani Neysiani
7th Apr 2023, 3:01 PM
Asma Sulthana
Asma Sulthana - avatar