0

I'm trying to run this Python program with Visual Studio Code:

# This Python program must be run with
# Python 3 as it won't work with 2.7.

# ends the output with a <space>
print("Welcome to" , end = ' ')
print("GeeksforGeeks", end = ' ')

But while building I get following output and error messages in console:

$ python /home/mrrobot/Documents/Python/loop_while.py
  File "/home/mrrobot/Documents/Python/loop_while.py", line 5
    print("Welcome to" , end = ' ')
                             ^
SyntaxError: invalid syntax

What could be the problem here? How can I fix it?

screenshot of VS Code

1
1

As @Eliah Kagan pointed out, the error occurs because your VS Code is using Python 2 as the interpreter. Switch to Python 3 interpreter in your VS Code and it should work.

P.S. Free PEP style tip: Write print('something', end=' '). When giving default values to parameters, avoid spacing around the = operator.

Not the answer you're looking for? Browse other questions tagged or ask your own question.