赞
踩
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.
下面的程序将用户的数字作为输入并找到其阶乘。
- 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
- 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
翻译自: https://www.thecrazyprogrammer.com/2017/04/python-program-find-factorial-number-using-loop.html
python 数字的阶乘
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。