首页 > 解决方案 > Codeforces 上的“输出格式错误,文件意外结束 - 预期令牌”错误

问题描述

Codeforces 的问题是:

- input w (watermelon weight) is between 1 and 100.
- if watermelon can be split into two parts, each weighing even number of kilos, print YES, otherwise print NO

我的代码(Python 3)是

w = input()
w = int(w)
if w >= 4 and w%2 == 0:
    print('YES')
else:
    print('NO')

当我输入时8,我得到输出YES,因为它应该是。

但是,当我提交我的文件时,它wrong answer to test 1

Input
8
Participant's output
Jury's answer
YES

Checker comment:
wrong output format Unexpected end of file - token expected

有人可以解释一下我错过了什么吗?我试图找到这个确切的错误并弄清楚但无济于事

标签: python

解决方案


在我朋友的帮助下解决了这个问题,所以我只想回答我自己的问题,以防其他人遇到同样的问题。

我使用 Jupyter notebook 来解​​决这个问题,所以我的文件有一个 .ipynb 扩展名,这就是为什么现场的求解器无法识别实际代码的原因。解决方案是上传一个 .py 扩展名(例如,在记事本中复制/粘贴代码并给它一个 .py 扩展名),然后它被接受了。


推荐阅读