x青年欢乐多 2020-06-06
from functools import reduce i = int(input("input a number 1-10: ")) result = reduce(lambda a, b: a*b, [item for item in range(1,i+1)]) print(f‘factorial of {i+1} is {result}‘)
运行结果
input a number 1-10: 5 factorial of 6 is 120
f = lambda x, y, z: x + y + z # returns a function that can optionally be assigned a name. def func: