I'm trying to figure out why this code works, specifically the math portion in the function's range. It goes as follows:
def factorial(x): total = 1 for t in range(1, x+1): total = total * t return total print total print factorial(4)
Why is it that when the function is executed, specifically the following section:
for t in range(1, x+1): total = total * t
the function executes (4*3*2*1) instead of ((1*4)+(1*3)+(1*2)+(1*1))? In other words, could you walk me through the math that's taking place?