运行时错误(NZEC)Python/Codech

2024-04-16 22:34:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我开始使用Codechef。我用python提交了以下代码来解决this question。在

下面的代码可以很好地与codechef的联机(python)IDE以及我的本地IDE一起使用。但是,当我在codechef上提交它时,会导致运行时错误(NZEC)。有人能解释一下这背后的原因吗?在

withdrawCash = int(input())
totalCash = int(input())
if withdrawCash < totalCash and withdrawCash % 5 is 0:
    totalCash = (totalCash - withdrawCash) - 0.5
    print(totalCash)

Tags: 代码inputif错误原因联机thiside
3条回答

问题是在一条线路上同时提供两个输入。代码在两行中等待输入。更改为:

withdrawCash,totalCash = map(int,raw_input.split())

NZEC(非零退出代码)发生在您的代码在退出时没有返回零。这可能是由于多种原因造成的,但是如果分割输入不能解决问题,请为EOFerror添加一个异常。写下:

try:
    withdrawCash = int(input().split())  # raw_input in the case of Python 2
except EOFerror: 
    print ("exit") # this is jst a pseudo statement `

正确使用缩进。我目前使用的是一个安卓的堆栈交换应用程序,在这个应用程序中编写代码并不容易。codechef对于Python来说是相当糟糕的。切换到CP的任何其他语言

尝试直接提交代码而不在codechefide上运行它,因为它与我也显示相同,但当我直接提交时,我成功地提交了。所以直接提交你的代码。在

相关问题 更多 >