我有下面的代码,用于计算阶乘
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))
例如阶乘5=120。这使用下面的代码工作
然而,当我使用pythonidle输入“1003”作为输入时,输出是6
有人能解释一下吗?下面是截图
重要提示:仅当我运行了两个测试时才会发生:
例如,试试999、1000、9000,然后再试试1003。在最后一次测试中,6作为输出出现。空闲时发生了什么导致这种情况
也许JS解决方案可以帮助您:
相关问题 更多 >
编程相关推荐