I’m not stuck on this one. However I am curious.
I understand that the following code works but I’m not understand why .
I’m having a hard time following each step of this code and what exactly is happening with range().
n = [3, 5, 7] def total(numbers): result = 0 for i in range(len(numbers)): result += numbers[i] return result
Additionally is there a situation where range() would be more suitable vs using code like this?
n = [3, 5, 7] def total(numbers): result = 0 for x in numbers: result += x return result
I find the second example very easy to follow through exactly what is happening. But not so much with the use of range().
Hopefully someone can simplify this for me.