![](https://img-blog.csdnimg.cn/img_convert/396a2ea957735e6f57da1463123d96c0.png)
python 数字的阶乘
Here you will get python program to find factorial of number using for and while loop.
在这里,您将获得python程序,以使用for和while循环查找数字的阶乘。
Factorial of a number is calculated by multiplying it with all the numbers below it starting from 1.
数字的阶乘是通过将其乘以1以下的所有数字来计算的。
For example factorial of 4 is 24 (1 x 2 x 3 x 4).
例如,阶乘4是24(1 x 2 x 3 x 4)。
Below program takes a number from user as an input and find its factorial.
下面的程序将用户的数字作为输入并找到其阶乘。
Python程序查找数字阶乘 (Python Program to Find Factorial of Number)
使用For循环 (Using For Loop)
num = int(input("enter a number: "))
fac = 1
for i in range(1, num + 1):
fac = fac * i
print("factorial of ", num, " is ", fac)
Output
输出量
enter a number: 5 factorial of 5 is 120
输入数字:5的5 阶乘是120
使用While循环 (Using While Loop)
num = int(input("enter a number: "))
fac = 1
i = 1
while i <= num:
fac = fac * i
i = i + 1
print("factorial of ", num, " is ", fac)
Output
输出量
enter a number: 4 factorial of 4 is 24
输入数字:4的 阶乘为24
影片教学 (Video Tutorial)
翻译自: https://www.thecrazyprogrammer.com/2017/04/python-program-find-factorial-number-using-loop.html
python 数字的阶乘