我如何使用vsc在python的同一行上接受多个整数?

时间:2019-06-28 08:01:54

标签: python visual-studio-code python-3.7

我在vsc中运行了一个代码,目的是查找大数字的最后一位。我只放置了相关的代码段。

  a,b=map(int,input().split())  
  aa=list(map(int,str(a)))  
  bb=list(map(int,str(b)))  

这会在vsc终端中产生以下错误:

Shaons-Air:VSC shaon$ python -u "/Users/shaon/Desktop/VSC/last.py"  
    4 3  
    Traceback (most recent call last):  
      File "/Users/shaon/Desktop/VSC/last.py", line 17, in <module>  
        a,b=map(int,input().split())  
      File "<string>", line 1  
        4 3   
    SyntaxError: unexpected EOF while parsing

1 个答案:

答案 0 :(得分:0)

根据您所写的内容,我可疑 Python的input()函数引发了一个EOFError,而我可疑与VSC运行有关带有-u选项的Python,它告诉Python不要缓冲来自标准输入的数据。 (顺便说一句,在发生错误之前了解您在Python提示符下键入的内容会很有帮助。)

无论如何,如果我在你的位置,接下来我要问的两个问题是:

首先,当您绕过VSC并直接在Windows cmd提示符下从Python运行Python脚本时会发生什么?这也给您nexpected EOF吗?

cd Users\shaon\Desktop\VSC
python -V                   rem Check the version number while we're here.
python -u last.py

如果不使用python选项运行-u会有什么不同?

第二,当用简单的回显循环替换代码并从VSC运行 that 时,会发生什么?这就是我所说的“简单回声循环”:

while True:
    msg = input() # Type your numbers here, or ctrl-c to exit the loop.
    print(msg)

如果我的猜想是正确的,那么当您直接从Python运行它时,您会发现您的代码可以工作,当您使用-u选项,并且当您从VSC运行回显循环时,您收到EOFError。在这种情况下,您可以尝试说服VSC以某种方式运行不带-u选项的Python。但是,让我们看看会发生什么。