简体   繁体   中英

Why is sometime my Visual studio code not working evrytime?

car = 'subaru'
>>> & C:/Users/ANTHONY/anaconda3/python.exe "d:/python programs vsc/login.py"
  File "<stdin>", line 1
^
SyntaxError: invalid syntax
 File "<stdin>", line 1

OR(check this program)

car = 'subaru'
print("Is car == 'subaru'? I predict True.")
print(car == 'subaru')
print("\nIs car == 'audi'? I predict False.")
print(car == 'audi')

>>> print(car == 'audi')
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
NameError: name 'car' is not defined

But this program works fine in python terminal or even in Juptyter notebook. I tried changing environments, sometimes it works fine.. other time it do not

The reason is that the content recognized by different terminals is different.

  1. Since "Python Interactive Terminal" is used for code interaction, it recognizes python code. Therefore, when the run button is clicked, (it executes python commands,) but the "Python Interactive Terminal" cannot recognize commands. Therefore, "SyntaxError: invalid syntax" is displayed.

    Solution: Please use the command " exit() " to exit this interactive window, or click the "Kill terminal" icon of the terminal, and then open a new terminal.

    在此处输入图像描述

  2. As for "NameError: name'car' is not defined", we need to input the value of the variable "car" and then use the output statement to judge it:

    在此处输入图像描述

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