階乗と順列の値を出力するPythonコード
階乗と順列の値をPythonで計算してみよう。
階乗と順列の値
数学の関数を利用するためにmath
モジュールを利用する。
階乗はmath.factorial()
関数を利用する。$n!$ を計算する場合は, factorial(n)
とする。
順列はmath.perm()
関数を利用する。${}_n \mathrm{P}_r$ を計算する場合は, perm(n, r)
とする。
Pythonコード入力例. $5!$ と ${}_{10} \mathrm{P}_4$ の値を出力する。
import math
print(math.factorial(5))
print(math.perm(10,4))
