【发布时间】:2017-08-29 23:34:38
【问题描述】:
我的代码中有一些重大错误,我不明白是什么原因造成的。我已经尝试更改我的退货声明的格式,但我一直收到同样的错误。
这是我当前的代码:
print("Kiran's Quiz: A quiz made by Kiran!\n")
def answers():
points = 0
x = input("Question 1: How far away is the Earth from the Sun? Give your answer in 'n million miles'.")
y = input("Question 2: What colour is white? Give your answer in 'x colour(s)'.")
z = input("Question 3: What temperature is boiling water? Give your answer in 'n degrees centigrade'.")
while (x != "93 million miles") or (y != "every colour") or (z != "100 degrees centigrade"):
print ("You got it wrong. -1 point for you!.")
points -= 1
print("You have" + str(points) + ("points.")
points += 1
print("Hooray, you got it correct! +1 to you!")
return x, y, z
answers()
我收到此错误:
Traceback (most recent call last):
File "python", line 17
return x, y, z
^
SyntaxError: invalid syntax
【问题讨论】:
-
在您的
while循环中,您的第二个print缺少右括号)。 -
return没有正确缩进 -
另外,
(points) - 1什么也不做。你必须points -= 1 -
return应该在def answer()中。你在外面写。 -
我上面的cmets中的每个人都是正确的。
标签: python-3.x return syntax-error