当阅读竞争网站上的一行时,即代码Ch

2024-05-20 02:44:33 发布

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

我尝试使用以下代码解决问题:

X,Y = map(float, input().split())

if X < Y and not X % 5:
    print(Y - X - 0.50)
else:
    print(Y)

当我使用IDLE运行时,这段代码给出了所需的输出。但是,当我尝试使用竞争性编程网站提供的解释器运行此代码时,我得到以下错误:

^{pr2}$

我试着阅读其他类似问题的答案,但似乎没有一个对我的情况有效。在


Tags: and代码mapinputif网站编程竞争性
3条回答

再看看codechef页面。请注意标记为“自定义输入”的复选框。选中/勾选后,将打开一个文本框,您可以在其中输入行。在

codechef image

竞争性编程网站很可能运行python2。python2对待input()的方式与python3不同。在

您应该使用raw_input(),而不是input()。在

从文件中:

raw_input() reads a line from input, converts it to a string (stripping a trailing newline), and returns that.

您的问题可以从解释的内容中得到解释here

In Python 2, raw_input() returns a string, and input() tries to run the input as a Python expression.

我不确定原因,但程序正在试图读取结束后的数据。您可以通过异常处理来解决这个问题

try:
    data = input()
except EOFError:
    break

相关问题 更多 >