Factorial


#1

Hi, please suggest why is the following throwing an error. Thanks.

import math
def factorial(x):
    fact = 0
    while x!= 0:
        fact = x * (x-1)
        x-=1
        if x == 0:
            x = 1
        print fact
    else:
        fact = 1
    print fact

Factorial
#2

you have an infinity loop. every time x becomes zero, you assign it a value of one

you should return the factorial, after it has been calculated. Currently your function returns None


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.