Practice makes perfect 5/15


#1

Can someone help me with my code? I think this should work

def factorial(x):
    total = 1
    a = 1
    if x >= a:
      total * a
      a += 1
    return total

but I got this error:
factorial(2) returned 1 instead of 2


#2

why do you use if? if only runs once, what if x=8? You need a loop

also, you multiply total * a, but do nothing with the result of this multiplication?


#3

Thank you! I changed if to while loop and total *= a and it worked!


#4