Can somebody explain why my method does not work. I used somebody else’s code to move on but I want to correct my mistakes.
I thought I could use a for loop to multiply the total each time by numbers of increment 1, starting from 1 and going to the number imputed. Then the elif was meant to handle the case if x was 1 or zero to begin with. I tried seeing what was going on with a print statement but It only ever gave me 0, 1, or none but I couldn’t understand why.
def factorial(x): total = 1 if x > 1: for y in range(1, x + 1): total = total * y return total elif x == 1 or x == 0: return 1