Ai
1 Star 0 Fork 0

Role/Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
factorial.py 640 Bytes
一键复制 编辑 原始数据 按行查看 历史
Ghulam Mohiyuddin 提交于 2019-10-19 15:01 +08:00 . Updated factorial.py
import math
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
n = int(input("Input a number to compute the factiorial : "))
print(factorial(n))
"""
Method 2:
Here we are going to use in-built fuction for factorial which is provided by Python for
user conveniance.
Steps:
-For this you should import math module first
-and use factorial() method from math module
Note:
Appear error when pass a negative or fraction value in factorial() method, so plz refrain from this.
Let's code it:
"""
if n>=0 :
print(math.factorial(n))
else:
print("Value of n is inValid!")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/CRole/Python.git
git@gitee.com:CRole/Python.git
CRole
Python
Python
master

搜索帮助