1 つの引数 (数値) を取り、その数値の階乗を返す関数を作成しようとしています。
たとえば、f(5) は 1*2*3*4*5 を返します。
私がこれまでに持っているのは
def product(n, term):
"""Return the product of the first n terms in a sequence.
term -- a function that takes one argument
"""
k, total = 1, 1
while k <= n:
k, total = k + 1, total * term(k, 1)
return total
def factorial(n):
"""Return n factorial by calling product.
>>> factorial(4)
24
"""
return product(n, mul)
しかし、項が引数を1つだけ取るようにすることは可能ですか?