私の解答
n = int(input())
ans = 1
for i in range(2,n+1):
ans = ans * i
print(ans)
解答例1
N = int(input())
factorial = 1
for i in range(2, N + 1):
factorial *= i
print(factorial)
解答例2
from math import factorial
N = int(input())
print(factorial(N))
- Python の場合、 math モジュールの factorial 関数を使用すると、階乗の計算を行うことができます。