运行时错误(NZEC) - Python / Codechef

时间:2015-12-11 06:21:43

标签: 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)

3 个答案:

答案 0 :(得分:0)

问题在一行中提供两个输入。您的代码等待输入2行。将其更改为:

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

答案 1 :(得分:0)

当您的代码在退出时没有返回零时,会发生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 `

正确使用缩进。我目前正在使用堆栈交换的Android应用程序,其中编写代码并不那么容易。在Python方面,codechef非常差。切换到CP的任何其他语言。

答案 2 :(得分:0)

尝试直接提交代码而不在Codechef ide上运行它,因为它对我来说也显示相同的内容,但是当我直接提交时,我成功提交了代码。所以直接提交您的代码。