【发布时间】:2021-12-06 23:12:30
【问题描述】:
一个数的阶乘是从 1 到该数的所有整数的乘积。
例如,6的阶乘是12345*6 = 720。阶乘没有定义为负数,0的阶乘是1, 0! = 1。
def recur_factorial(n):
if n == 1:
return n
else:
return n*recur_factorial(n-1)
num = 7
# check if the number is negative
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
print("The factorial of", num, "is", recur_factorial(num))
【问题讨论】:
-
这里有两行代码可以帮助您入门
command = input("enter command: ").split()和print command -
在输入示例中,
IA B引用了一个尚未使用IV添加的顶点——它仅出现在第三个输入中。因此,您当前的代码会产生错误。请解释这种情况下所需的行为。 -
这能回答你的问题吗? Are there a way to use while loop function as a list tracker? and mix with FileI/O? 它基本上和你问的一样,除了维护一个待办事项列表而不是维护一个图表。
-
非常感谢你们的帮助!!
标签: python algorithm python-2.7 python-requests