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?

1
  • 3
    This is on-topic and should be reopened. It comes down to how to use development tools and what the python command is in Ubuntu. See the answer below on configuring VS Code, and Why is Python 2.7 still the default Python version in Ubuntu? As the help center says, the scope of this site includes "Development on Ubuntu". Opinion differs on how broadly we should understand that, but it's entirely meaningless if it doesn't at least include questions about tooling and about problems that appear because Ubuntu is different from other OSes. This is both. Aug 10, 2020 at 20:29

2 Answers 2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .