【问题标题】:I tried running a python file in terminal on Visual Studio code, but it keeps giving me synthax error我尝试在 Visual Studio 代码的终端中运行 python 文件,但它一直给我 synthax 错误
【发布时间】:2020-11-26 08:01:50
【问题描述】:
print("Hi!")
name = input("what's your name? ")

print("It's nice to meet you,", name)
answer = input("Are you enjoying the course? ")

if answer =="Yes":
print("That's good to hear!")
else:
print("Oh no! That makes me sad!")

上面是代码,但下面总是出现这种语法错误

 Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32   
Type "help", "copyright", "credits" or "license" for more information.
>>> & C:/Users/gbemi/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/gbemi/Desktop/exercise files/chap01/01_03.py"
  File "<stdin>", line 1
    & C:/Users/gbemi/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/gbemi/Desktop/exercise files/chap01/01_03.py"
    ^
SyntaxError: invalid syntax
>>>

我已经去文件首选项设置检查路径,它是正确的。请问有什么问题,我是新手程序员。

【问题讨论】:

  • 您需要缩进打印语句。在您的错误部分,您已经在 Python 命令行中。输入quit(),然后运行命令C:/Users/gbemi/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/gbemi/Desktop/exercise files/chap01/01_03.py"

标签: python-3.x input visual-studio-code terminal notepad


【解决方案1】:

给代码适当的缩进。然后只有它会起作用。

像这样:

print("Hi!") 

name = input("what's your name? ")

print("It's nice to meet you,", name) 

answer = input("Are you enjoying the course? ")

if answer =="Yes": 

       print("That's good to hear!") 

else: 

       print("Oh no! That makes me sad!") 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 1970-01-01
    • 2019-08-03
    • 2019-12-06
    • 1970-01-01
    • 2021-05-26
    • 1970-01-01
    相关资源
    最近更新 更多