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)
        if x == 0:
            x = 1
        print fact
        fact = 1
    print fact


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


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