どうも、ちょげ(@chogetarou)です。
mathを使ってNの階乗を求める方法を紹介します。
方法

mathを使ってNの階乗を取得するには、factorial()を使います。
まず、mathをインポートします。
import math
mathからfactorial()を呼び出します。
そして、factorial()の引数に数値を指定します。
math.factorial(N)
math.factorial()は、引数に指定した数値の階乗を返します。
使用例
import math
print(math.factorial(3))
print(math.factorial(5))
print(math.factorial(7))
出力:
6
120
5040
コメント