Although I have passed Codecademy loop lesson, but I still don’t understand how to use loops correctly. In other words, I really have a big problem in using loops . For example:
def over_nine_thousand(lst): all_sum = 0 for i in lst: all_sum += i return all_sum print(over_nine_thousand([8000, 900, 120, 5000])) # prints 8000 instead of 14020
In the code above, I want to sum all list numbers with function called
over_nine_thousand that takes in
lst as a parameter but
print(over_nine_thousand([8000, 900, 120, 5000])) only prints the first element 8000. Why is this happening ?? please help me understand how loops actually work and how to use
range() function because whenever I write loops, they don’t work correctly.