[Solved] Number plus number from array in loops [duplicate]


Just add a += and a new variable like so:

number = [1, 2, 4, 5, 6]
y = 0 #new variable (output variable)
for x in number:
    y += x #add = sign here

print(y)

Output:

18

But it would be better to use:

y = sum(number)
print(y)

Output:

18

28

solved Number plus number from array in loops [duplicate]