【问题标题】:Python: HELP getting runtime error(NZEC)Python:帮助出现运行时错误(NZEC)
【发布时间】:2016-12-27 20:37:24
【问题描述】:

所以我决定在 CodeChef 上从事有竞争力的编程工作。我看到了一个要尝试的问题。但是我不断收到运行时错误(NZEC),我不知道为什么,因为我认为只有在调用超出绑定数组项和无限循环时才会发生错误,这会占用太多内存。

问题
1.) 获得 2 个输入 A 和 B
2.) 边界:1 ≤ B 3.) 然后我做 A-B 并更改答案的一位数
4.) 然后我把它退回去

注意: 时间限制为 1 秒,最大源代码大小 50,000 字节

例如

input A >> 95
input B >> 50

output >> 35

实际答案是 45,但我们打算更改答案的一位数

这就是我的解决方案

from random import randint

test1 = True
test2 = True

while test1:
    A = int(input("Enter a number: "))
    if (A>=1) and (A<=10000):
        test1 = False
    else:
        print("Number must be greater or equal to 1 and less than or equalts to 10,000")


while test2:
    B = int(input("Enter a second number: "))
    if (B>=1) and (B<=10000) and (B<A):
        test2 = False
    else:
        print("Number must follow rules as above BUT must be less than your first")

solution = str(A-B)
range1 = randint(0, len(solution)-1)
range2 = randint(0,9)
replacement = list(range(0,10))

new_solution = solution.replace(solution[range1], str(replacement[range2]))
print(new_solution)

【问题讨论】:

    标签: python python-3.x runtime-error


    【解决方案1】:

    “NZEC”不是一个特定的错误,我们可以很容易地查明并说出它的原因。它只是意味着“非零退出代码”。这可能意味着您的代码中某处发生了错误,或者您的代码执行时间太长(这些在线判断通常有严格的运行时限制)。

    一个可能的原因是在线法官尝试使用字符串输入执行您的代码,这导致您对int(input(..)) 的调用引发了您的代码无法捕获的ValueError

    【讨论】:

    • 我查看了其他答案。他们甚至没有包含用于测试用户是否遵循边界的代码。所以可以肯定的是,字符串输入测试可能不是运行时限制的问题,但我不确定。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多