[英]OJ says compile error about my python program even if it runs well on my computer (ubuntu 18.04)
i wrote a simple python program for my homework that wants us to add up three integers given from input.我为我的作业编写了一个简单的 python 程序,它希望我们将输入的三个整数相加。 i submitted it to my school's oj (online judge) system, but i got "compiler error"
我将它提交给我学校的 oj(在线法官)系统,但我收到了“编译器错误”
the program runs very well on my personal computer that runs ubuntu 18.04 amd64, but i can't get it pass the oj test.该程序在运行 ubuntu 18.04 amd64 的个人计算机上运行良好,但我无法通过 oj 测试。 i sincerely don't know what went wrong because the oj didn't give any message, only a final status "compiler error"
我真的不知道出了什么问题,因为 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}")
here's the result when i run my program on my computer:这是我在计算机上运行程序时的结果:
ubuntu@VMware:~/python-intro $ python3 1003.py
3
4
5
The answer is 12
and my computer system:和我的电脑系统:
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
how can it be a compiler error on the oj??怎么可能是 oj 上的编译器错误? i have confirmed that my submission language is "python 3" not "python 2" or whatever.
我已经确认我的提交语言是“python 3”而不是“python 2”或其他语言。
Maybe the python 3 version of your OJ is not python 3.6.也许你的 OJ 的 python 3 版本不是 python 3.6。 And you can't use f-string on python versions below 3.6.
并且您不能在低于 3.6 的 Python 版本上使用 f-string。
I suggest to change your string format to:我建议将您的字符串格式更改为:
print("The answer is {answer}".format(answer=answer))
f-strings were introduced in Python 3.6. f 字符串是在 Python 3.6 中引入的。 In an earlier Python, this line is a syntax error:
在早期的 Python 中,这一行是一个语法错误:
print(f"The answer is {answer}")
To ensure compatibility, rewrite it to为确保兼容性,将其重写为
print("The answer is %s" % answer)
The problem is mostly related to f-string as Amadan pointed out.正如阿马丹指出的那样,问题主要与 f-string 有关。
print(f"The answer is {answer}") <<< print(f"答案是{answer}") <<<
change this with format usage and update the thread.使用格式使用更改此设置并更新线程。
print("The answer is {}".format(answer)) print("答案是{}".format(answer))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.