def jiecheng(num,result): if num>1: result = num*result num-=1 jiecheng(num,result) else: print('result=', result) # jiecheng(5, 1) def jiecheng2(num,result): for i in range(1,num+1): # print(i) result*=i print('result=',result) # jiecheng2(5,1) from functools import reduce def jiecheng3(num): result = reduce(lambda x,y:x*y,range(1,num+1)) print(result) # jiecheng3(5)