0

I am getting this error while running a simple code using Visual Studio Code's CodeRunner extension while print values in the same line separated using a space in python.

for i in range(0,6):
    print(i, end = ' ')

Error: print(i, end = ' ') SyntaxError: invalid syntax. However, the same code runs I select 'Run Python File in Terminal' Please help me out on this issue and suggest possible alternatives/fixes.

  • I am unable to reproduce the results with my vscode and "CodeRunner" extension for vscode. Numbers print to the same line for me. Could you provide the versions of both these you are using? – Bdyce Aug 26 '20 at 19:31
  • my CodeRunner version is 0.11.0, VSCode version is 1.48.2 –  Aug 26 '20 at 19:35

1 Answers1

1

The reason you are getting SyntaxError has to do with your python terminal version being different than the one you've told vscode to use and therefore the one coderunner uses. You can change the vscode python interpreter (version) by using CTRL+SHIFT+P in vscode. This will bring up the Command Pallet where you can type in python select interpreter and select the version of python that matches your terminal version.

If you don't know which version of python your terminal version is that is running the code correctly, go to the terminal and type python --version

Bdyce
  • 332
  • 2
  • 11
  • My python interpreter is set to 3.7.3 64bit as installed from VScode extensions. Similarly, in my macbook air, the default python3 version is also 3.7.3. Yet, when I try to run using CodeRunner, I am getting the same syntax error, however I am able to print the numbers using 'Run by terminal' –  Aug 27 '20 at 06:45
  • I am unable to provide much more advice other than to say re-install the extensions in dependant order or to look into the documentation of the extensions mentioned. – Bdyce Aug 27 '20 at 16:15
  • https://stackoverflow.com/questions/19797616/coderunner-uses-old-2-71-version-of-python-instead-of-3-2-on-osx-10-7-5 – Bdyce Aug 27 '20 at 16:17
  • Yup, that link really helped! Thanks a lot! –  Aug 27 '20 at 21:16