0

I ran a code(in vsc) whose purpose is to find the last digit of large numbers.I am putting up only the relevant code snippet.

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

This generates the following error in vsc terminal:

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
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • Use raw_input instead of input. Reference: https://stackoverflow.com/questions/5074225/python-unexpected-eof-while-parsing – hsen Jun 28 '19 at 08:06
  • @hsen Hey this is python 3.7. raw_input is invalid here –  Jun 28 '19 at 08:09
  • Are you sure you are executing this with Python3 ? did you check the interpreter you are using in vsc ? try `import sys print(sys.version)` – Touk Jun 28 '19 at 08:57

1 Answers1

0

From what you write, I suspect Python's input() function raised an EOFError, and I suspect it has something to do with VSC running Python with the -u option, which tells Python not to buffer the data coming in from standard input. (It would be helpful, by the way, to know what you typed into the Python prompt before your error occurred.)

Anyway, if I was in your place, the next two questions I would ask would be these:

First, what happens when you bypass VSC and run your Python script directly from Python on the Windows cmd prompt? Does that give you an nexpected EOF, too?

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

What difference, if any, does it make when you run python without the -u option?

Second, what happens when you replace your code with a simple echo loop and run that from VSC? Here is what I mean by "simple echo loop":

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

If my suspicion is correct, you will find that your code works when you run it directly from Python, fails (with an EOFError) when you run it with the -u option, and that you will get an EOFError when you run the echo loop from VSC. In that case, you might try persuading VSC to run Python without the -u option somehow. But let's see what happens.

  • Hey dude,what is this -u option? –  Jun 28 '19 at 16:37
  • It's the "-u in "python -u", which in turn is part of VSC's invocation "VSC shaon$ python -u "/Users/shaon/Desktop/VSC/last.py" ". The "-u" option changes how the Python interpreter reads data from standard input, and I suspect this change might cause the input() function to run into those "unexpected end-of-file" error. That's why I'm asking what happens when you run python without this option. – Thomas Blankenhorn Jun 28 '19 at 20:05