我已阅读其他问题和答案,但无法实现我的代码的任何解决方案。对于这段代码给出运行时错误的原因,我仍然无能为力。为什么这个Python代码给运行时错误(NZEC)?
我试图在CodeChef上提交代码,但是它给出了运行时错误(NZEC),尽管代码在我的控制台上完美地运行了一些输入。这里是我的代码:
def GetSquares(base):
if not base or base < 4:
return 0
else:
x = (base - 4) - (base % 2) + 1
return x + GetSquares(base - 4)
num_test = int(input())
for test in range(num_test):
base = int(input())
print (int(GetSquares(base)))
Codechef的解释NZEC:
NZEC stands for Non Zero Exit Code. For C users, this will be generated if your main method does not have a return 0; statement. Other languages like Java/C++ could generate this error if they throw an exception.
的问题,我试图解决:
https://www.codechef.com/problems/TRISQ
如果我不得不猜测,int()转换失败,因为输入不是一个有效的整数。如果可以,请在做任何事之前尝试打印它 - 你确定你不应该分裂它或什么?我的猜测是你正在经历一个(heh)堆栈溢出 – James
程序运行什么输入?程序不能运行什么输入? – Harrison
崩溃时的输入是什么? –