【问题标题】:Why is codechef's Python 3.6 compiler repeatedly mentioning EOF error? In PyCharm this code works properly however为什么 codechef 的 Python 3.6 编译器反复提到 EOF 错误?但是在 PyCharm 中,这段代码可以正常工作
【发布时间】:2021-10-14 01:31:02
【问题描述】:

这是我用 PyCharm 编写的程序。它在 PyCharm IDE 中运行良好,但在 Codechef 的编译器中显示 EOF 错误。请提及错误的原因以及什么是 EOF 错误。谢谢!!

try:
    T = int(input())
    S = []
    N = []
    K = []
    c = ''
    for i in range(T):
        x, y = input().split()
        N.append(int(x))
        K.append(int(y))
        ele = input()
        ele = ele.split()
        for j in range(len(ele)):
            ele[j] = int(ele[j])
        S = ele
        S.sort()
        S.reverse()
        count = 0
        for l in range(N[I]):
            if S[l] >= S[K[i]-1]:
                count += 1
        c += str(count) + " "
    print(c)
except EOFError as e:
    print(e)

【问题讨论】:

    标签: python runtime-error eof


    【解决方案1】:

    它是解释器,而不是编译器。

    一个EOF错误是一个异常,不是错误,常见于input(),意思是行尾。这是当您的输入到达行尾时。

    这是因为 PyCharm 通过询问来提供输入,强制你提供输入,如果它强制你提供输入,它就无法到达行尾,因为它不可能强制你在到达结尾之前提供东西行的。

    #Be careful with these in CodeChef and be very precise where you put them and do not overuse them.
    MyVariable=input()
    Some=input()
    print("ETC.")
    

    CodeChef 不会强迫你这样做,所以它允许你让它走到行尾。

    【讨论】:

    • 是的,我是对的!在每个交互式控制台 Python 解释器中,它不会抛出 EOF,但在 STDIN 中会抛出。此外,另一个错误是完全不同的事情,根本与此无关,所以不要质疑我的解决方案。干杯!
    猜你喜欢
    • 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
    相关资源
    最近更新 更多