【问题标题】:Python - print("abc") giving a syntax errorPython - print("abc") 给出语法错误
【发布时间】:2016-04-18 16:04:56
【问题描述】:

此打印函数出现语法错误,无法找出原因!

if teacher == "no":
    name = input("What is your name?")
    class_code = str(input("What class are you from? 1, 2 or 3?")
    print("Welcome to the Arithmetic Quiz, ",name)

感谢您的帮助!

【问题讨论】:

  • 你是在使用python 2解释器来运行python 3代码吗?
  • @BlackBear 此处显示的print 在 Python 2 和 Python 3 中均有效。
  • 如果这是 Python 2,您应该使用 raw_input,而不是 input。 Python 3 中的input 和Python 2 中的raw_input 都返回字符串,因此不需要调用str()

标签: python syntax syntax-error


【解决方案1】:

改变这一行

class_code = str(input("What class are you from? 1, 2 or 3?")

class_code = str(input("What class are you from? 1, 2 or 3?"))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    相关资源
    最近更新 更多