在 vscode 中对 运行 python 文件使用代码-运行ner 时发生错误

Error occurred when using code-runner to run python file in vscode

这是一个非常简单的程序,它获取用户输入并在无限循环中将其打印出来,如下所示:

while True:
    s = input('Enter something: ')
    print(s)

但是当我输入“Hello world”时,我得到了以下输出:

Enter something: Hello world
Traceback (most recent call last):
  File "/Users/chuyizhang/Documents/python/break.py", line 2, in <module>
    s = input('Enter something: ')
  File "<string>", line 1
    Hello world
              ^
  SyntaxError: unexpected EOF while parsing

或者可以是:

Enter something: Hello
Traceback (most recent call last):
  File "/Users/chuyizhang/Documents/python/break.py", line 2, in <module>
    s = input('Enter something: ')
  File "<string>", line 1, in <module>
NameError: name 'Hello' is not defined  

当我输入“你好”时

当我输入三个或更多单词时,我会得到:

Enter something: Hello world hello world
Traceback (most recent call last):
  File "/Users/chuyizhang/Documents/python/break.py", line 2, in <module>
    s = input('Enter something: ')
  File "<string>", line 1
    Hello world hello world
              ^
SyntaxError: invalid syntax 

那我该如何解决呢?这是否意味着代码运行程序扩展或 vscode 配置有问题?

您在 SyntaxError: unexpected EOF while parsing 中遇到的问题。它可能由于多种原因导致版本 conflict, indentation, syntaxt error etc.

你的答案可能是here