【问题标题】:How do I fix this line of code so that I don't get any syntax errors?如何修复这行代码,以免出现任何语法错误?
【发布时间】:2021-05-09 01:07:22
【问题描述】:

我是新手,所以请放轻松。

我不断收到本节的语法错误代码(特别是“print()”,但不知道我做错了什么?谁能给我看看并告诉我?

def name():  
    NAME=str(input("Why don't you introduce yourself to them, now that you've caught their eyes?")
    print(,NAME, "? Is that right? -yes/no-")
    answer = input(">").lower()

【问题讨论】:

  • print 行中删除第一个逗号(,)怎么样?此外,您的第二行最后还需要一个 )
  • 两件事,从第 3 行删除 , 并在 NAME 末尾添加一个额外的 )

标签: python syntax


【解决方案1】:

这里是固定代码:

def name():  
    NAME = input("Why don't you introduce yourself to them, now that you've caught their eyes?")
    print(NAME, "? Is that right? -yes/no-")
    answer = input(">").lower()

【讨论】:

    【解决方案2】:

    您的代码中有两个语法错误。

    第一个是你在第 2 行末尾缺少)。第 2 行应该是这样的

    NAME=str(input("Why don't you introduce yourself to them, now that you've caught their eyes?"))

    您的第二个语法错误是您的第一个变量前面有一个 , 逗号。 去掉那个逗号,让你的第三行看起来像这样

    print(NAME, "? Is that right? -yes/no-")

    【讨论】:

      【解决方案3】:

      你错过了 str 函数的 ')' 和下一行你在 print 函数中有额外的 ','

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-04-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-10
        • 1970-01-01
        • 2019-12-30
        相关资源
        最近更新 更多