python 数字的阶乘_Python程序使用循环查找数字阶乘

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 数字的阶乘

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值