How to compute factorial of a number until the result is one digit in Python

1 Answer

0 votes
def factorial(num):
    x = 1
    for ch in str(num):
        if ch is not '0':
            x *= int(ch)
            print("x = ", x)
    return x

n = 12345
while n > 10:
    n = factorial(n)
    print("  n = ", n)


'''
run:

x =  1
x =  2
x =  6
x =  24
x =  120
  n =  120
x =  1
x =  2
  n =  2

'''

 



answered Nov 30, 2017 by avibootz
...