简体   繁体   中英

VSCode Python - print statement not printing to output

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.

在此处输入图像描述

What am I doing wrong?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM