2

I have written a Python 3 code, which is:

i = int(input("enter number: "))
print("enter",i)

I'm expecting an output as:

enter number: 5
enter 5

However, I'm getting this:

enter number: 5
('enter', 5)

What could be the issue? How can I rectify this?

Eliah Kagan
  • 119,640

2 Answers2

4

You are using Python 2. To use Python 3 you need to change the Python interpreter in Visual Studio Code. See instructions on Using Python Environments in Visual Studio Code You need to go to command pallete and use python:select interpreter and select Python 3 interpreter.

In Python 3 you should get the following output.

enter number: 7
enter 7
Kulfy
  • 18,154
A.Sha
  • 616
0

I was having the same issue. On vscode, if you using the "Code Runner" extension (by Jun Han), you need to check if the "Code Runner" extension interprets the code - with python or with python3. Check on the vscode's output how "Code Runner" interprets the code. On my end was on the following way:

[Running] python -u "/home/martin/hello_world.py"

As you can see the extension was using python instead of python3. You need to go to the "Code Runner" extension settings and edit them by clicking on "Edit in settings.json". Then change the "python" value to "python3 -u" instead of "python -u". It needs to be: "python": "python3 -u" - save the changes you made and that's it.

See the screenshots I made:

Screenshot 1 Screenshot 2