# 题目:利用递归方法求n!
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
n = int(input("请输入n = "))
print("n! = %d" % factorial(n))
运行结果:
# 题目:利用递归方法求n!
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
n = int(input("请输入n = "))
print("n! = %d" % factorial(n))
运行结果: