在命令行运行方法test.py --id 1234
来个面试遇到题目,求斐波那契第n个数的阶乘。
import click from functools import reduce def fibo(n): a,b = 0,1 count = 1 while count<=n: a,b = b,a+b if count == n: print(a) return a count+=1 @click.command() @click.option('--n', default='123',type=int,help='add num') def run(n): num = fibo(n) res = reduce(lambda x,y: x*y,range(1,n+1)) print(f"{res=}") if __name__ == '__main__': run()运行方式:python3 1.py --n 5
转载于:https://www.cnblogs.com/c-x-a/p/9767103.html