初学者Python 3语法

Tir*_*tel 2 python syntax python-3.x

我一直在用python编写一个简单的测验,但在我的Python GUI中继续得到"SyntaxError:在编译单个语句时找到多个语句".请帮忙.

print("Welcome to my quiz!")
score = 0
question1 = str(input("What colour is a banana."))
if question.lower() == 'yellow':
    print("Correct. The answer is", question1)
    score = score + 1
else:
    print("Incorrect. The answer is yellow, not", question1)
print score
Run Code Online (Sandbox Code Playgroud)

Hen*_*ter 8

你有几个问题.首先,question没有定义(第4行); 那应该是question1.其次,print是Python 3中的一个函数,所以你的最后一行应该是print(score).第三,input已经返回一个字符串,所以你不需要str调用.所以第3行应该是这样的:

question1 = input("What colour is a banana.")
Run Code Online (Sandbox Code Playgroud)

  • python 3中没有`raw_input`. (2认同)