编写?compute_factorial.py 如下
# -*- coding: utf-8 -*-
""" 计算阶乘 factorial """
import sys
from functools import reduce
#help(reduce)
if len(sys.argv) ==2:
n = int(sys.argv[1])
else:
print('usage: python compute_factorial.py n ')
sys.exit(1)
#n = 30
factorial = reduce(lambda x,y: x*y, range(1,n+1))
print(f"{n}!= {factorial}")
运行 python?compute_factorial.py 30