0

Adding a list function

Write a function that accepts a list of integers and returns the sum of all the numbers in the list. Assume that the input list contains only numbers. Do NOT use the built-in sum() function. a = [5,6,8,9,7,6] total = 0 def add_num(a): for n in a: total = total + n return total print(add_num(a))

1st Feb 2022, 9:51 PM
Knowledge Is Power
Knowledge Is Power - avatar
2 Respostas
+ 2
the return is inside the for loop that stops the loop put it outside
1st Feb 2022, 10:13 PM
L.M.Paredes
L.M.Paredes - avatar