python - OJ 说我的 python 程序编译错误,即使它在我的计算机上运行良好(ubuntu 18.04)

标签 python python-3.x syntax-error

我为我的作业编写了一个简单的Python程序,它希望我们将输入给出的三个整数相加。我将其提交给学校的oj(在线法官)系统,但我收到“编译器错误”

该程序在我运行 ubuntu 18.04 amd64 的个人计算机上运行得很好,但我无法让它通过 oj 测试。我真的不知道出了什么问题,因为 oj 没有给出任何消息,只有最终状态“编译器错误”

import sys

a = input()
b = input()
c = input()
a = int(a)
b = int(b)
c = int(c)
answer = a + b + c
print(f"The answer is {answer}")

这是我在计算机上运行程序时的结果:

ubuntu@VMware:~/python-intro $ python3 1003.py
3
4
5
The answer is 12

和我的计算机系统:

ubuntu@VMware:~/python-intro $ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:        18.04
Codename:       bionic

怎么会是oj上的编译错误呢?我已确认我的提交语言是“python 3”而不是“python 2”或其他语言。

最佳答案

也许你的 OJ 的 python 3 版本不是 python 3.6。并且您不能在低于 3.6 的 python 版本上使用 f-string。

我建议将您的字符串格式更改为:

print("The answer is {answer}".format(answer=answer))

关于python - OJ 说我的 python 程序编译错误,即使它在我的计算机上运行良好(ubuntu 18.04),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53919422/

相关文章:

Python强制条件

python - 使谷歌分析 ID 成为一个变量

python - Pandas csv itertools 组合

python - 如何创建两个独立的 pygame 显示?如果我不能,我如何创建 pygame 的两个实例?

python - 从网络创建数据库

Python、Postgres 和具有空值的整数?

python - 在ElasticSearch中如何检查字段是否存在,然后应仅返回 bool 值(True或False)

python - 根据较长的字符串压缩字符串

bash shell 脚本语法错误

json - 结构化数据测试工具显示 JSON-LD 语法错误 : "value, object or array expected"