0

vscode IDE show me an error on using { print(i,end=' ') } with python language

I have used pycharm IDE and it works correctly ...

def showDivisor(number):
    for i in range(1, number+1):
        if number % i == 0:
            print(i, end=' ')

showDivisor(24)

enter image description here

3
  • You are running on Python 2. Commented Aug 24, 2019 at 14:51
  • I use python 3,you can see that in the first line of terminal output on the picture attached Commented Aug 24, 2019 at 15:24
  • Nothing in that line indicates a specific Python version. The Syntax error on the other hand is typical for running code with a Python 3 print() function on Python 2. Commented Aug 24, 2019 at 15:57

2 Answers 2

1

Running your code in Python 3.6.5 => no problems.

Running with Python 2.7.13 => the given syntax error.

Click in the lower left in the status line on the Python word and select Python 3.x

You can check which python interpreter is used by looking in the settings of the workspace.

Sign up to request clarification or add additional context in comments.

Comments

1

You are executing your code via the Code Runner extension, not the Python extension, and so the selected interpreter for the latter is not informing the former. Either use the Python extension to run your code via Run Python File in Terminal or you need to configure the Code Runner extension to use Python 3.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.