I am supposed to use a while loop to find the sum of a list until it reaches a negative number or until it reaches the end of the list. Here are example lists:
v = [ 10, 12, 3, -5, 5, 6 ]
v = [ 0, 10, 3, 6, 5, 1 ]
The output total sum for both lists should be 25. Here is my code:
result = 0
i = 0
for num in v:
while num >= 0:
result += num
i += 1
print(result)
For both of the lists, my output is just a blank infinite loop. The code I provided was the code I thought made the most sense.