**阶乘**
'''
1*1
1*2
1*2*3*4
1*2*3*4*5
1*2*3*4*5*6
1*2*3*4*5*6*7
sum1(1)*2=sum(2)
sum1(2)*3=sum(3)
sum1(3)*4=sum(4)
sum1(4)*5=sum(5)
sum1(5)*6=sum(6)
sum1(6)*7=sum(7)
'''
def sum1(n):
'''
递归实现阶乘
:param n: 值
:return: n!
'''
if n==1:
return 1
else:
return n*sum1(n-1)
print(sum1(10))
def func2(num):
'''
普通方法实现阶乘
:param num: 参数
:return: n!
'''
i = 1
res = 1
while i<=num:
res=res*i
i+=1
return res
print(func2(1))
print(func2(2))
print(func2(3))
print(func2(4))