Glam Prestige Journal

Bright entertainment trends with youth appeal.

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?

1

2 Answers

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 CodeYou 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

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 1Screenshot 2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy