math モジュールに factorial 関数がありますよ。
python
1>>> import math
2>>> help(math.factorial)
3Help on built-in function factorial in module math:
4
5factorial(x, /)
6 Find x!.
7
8 Raise a ValueError if x is negative or non-integral.
9
10>>> math.factorial(30)
11265252859812191058636308480000000
for関数やwhile関数を使う方法はありませんか?
python
1def my_factorial(n):
2 fact_n = 1
3 for i in range(2, n+1):
4 fact_n *= i
5
6 return fact_n
7
8print(my_factorial(30))
9
10#
11265252859812191058636308480000000
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/11/09 17:11
2021/11/09 17:27