#本文档计算N的阶乘,import functools#利用for循环计算def fract(n):r = 1if n<1 :print("N不能小于1")returnelse:for i in range(1,n + 1):r *= i#print(r)return r#递归调用def fract1(n):r = 1if n<1 :print("N不能小于1")returnelif n == 1:return 1else:r = fract1(n-1) * nreturn r#调用functools.reduce函数def fn( x, y):return x*ydef fract2(n):r = 1if n<1 :print("N不能小于1")returnelse:return functools.reduce(fn,range(1,n+1))#使用lambda关键字def fract3(n):r = 1if n<1:print("n不能小于1")returnelse:return functools.reduce(lambda x,y: x*y,range(1,n+1))#根据不同的函数调用输出print(fract(4))print(fract1(5))print(fract2(6))print(fract3(7))