Hi guys, I have passed this question 13/15 - product. At first I didn't, using the code below:
def product(lst): for i in range(len(lst)): total = 1 total *= lst[i] return total
After that I amended my code by shifting the 'total = 1' outside the loop:
def product(lst): total = 1 for i in range(len(lst)): total *= lst[i] return total
I am a total novice in IT and programming, and I am embarrassed to say that to date, I can still get confused about loops, especially when it comes to yielding a total amount. Can someone please explain to me how 'total = 1' inside and outside the loop work differently? Really appreciate your kind help.