我已閱讀其他問題和答案,但無法實現我的代碼的任何解決方案。對於這段代碼給出運行時錯誤的原因,我仍然無能爲力。爲什麼這個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
崩潰時的輸入是什麼? –