def factorial(x): count=x while count>1: total=x*(x-1) count-=1 return total print factorial(3)
total is defined in the loop, so it will simply be assigned a new value (overwriting the previous value), not adding the value total, so total is never a true total
define total outside the loop so you can add values to it so you end up with the factorial
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.