I was doing a kind of simple Python exercise, the idea was to create a function that adds the numbers of a list. The problem is that when I run it the for
loop skips several integers and I don't know why.
def simplearraysum(ar):
sum = 0
for number in ar:
sum = sum + number
ar.remove(number)
return sum
list = [1, 2, 3, 4, 10, 11]
print(simplearraysum(list))
The output is 14, but it should be 31.