下面是一个用Python编程求阶乘和数的例子:
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n-1)
def factorial_sum(n):
digits = [int(digit) for digit in str(n)]
factorial_sum = sum(factorial(digit) for digit in digits)
return factorial_sum
# 测试
num = 145
result = factorial_sum(num)
print("阶乘和数为:", result)
运行这段代码,输出结果为:
阶乘和数为: 145
这说明145是一个阶乘和数。
1