I was trying to solve Functions:Fundamentals, 1/14 screen. The instructions are as follows:
- Compute the sum of
a_list
(already defined in the code editor) without usingsum()
.
- Initialize a variable named
sum_manual
with a value of0
. - Loop through
a_list
, and for each iteration add the current number tosum_manual
.
- Print
sum_manual
andsum(a_list)
to see if the values are the same.
The answer to this is:
a_list = [4444, 8897, 6340, 9896, 4835, 4324, 10, 6445,
661, 1246, 1000, 7429, 1376, 8121, 647, 1280,
3993, 4881, 9500, 6701, 1199, 6251, 4432, 37]
sum_manual= 0
for list_element in a_list:
sum_manual += list_element
print(sum_manual)
print(sum(a_list))
Can someone explain to me why do I need to use list_element instead of just element for the loop?