VSCode Python - print statement not printing to output

Viewed 8388

I am new to VSCode. I have set it up on Windows. When I run it using Code Runner,I see Running and Done messages but the print statements are not working.

print("Hello World!")
print ("This is VS Code")
a=1
while a <10:
    print a
    a = a+ 1

Here is the output:

[Running] python -u "c:\Users\user\PythonWorkArea\VSCode\HelloWorld\app.py"
[![\[Done\] exited with code=0 in 0.293 seconds][1]][1]

The print statement is not working.

enter image description here

What am I doing wrong?

4 Answers

You should select the appropriate Python Environment that you are using, do Control+Shift+P -> Python: Select Interpreter.

I had the same issue and had to change the default env to get it working.

Try this:

print("Hello world!")
print("This is VS Code")
a = 0
while a < 10:
    print(a)
    a += 1

"a" has not been defined. Im surprised you did not get an "undefined error" msg instead. This should work tho...

a = 0

while(a < 10):
  print(a)
  a +=1

The easiest way to achieve this is by installing the Coderunner extension. It will automatically show your print statements in your VS Code terminal.

Related