我在第6年,我正在编写一个Python测验(仅仅是为了好玩)而且我遇到了一个重大问题。退货声明不起作用。 这是我目前的代码:
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
另外,如果你有足够的时间,这是我的代码的旧版本:
print("Kiran's Quiz: A quiz made by Kiran!\n")
def answers(x, y, z):
points = 0
x = input("Question 1: How far away is the Earth from the Sun?")
y = input("Question 2: What colour is white?")
z = input("Question 3: What temperature is boiling water?")
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(x, y, z)
我一直接受这个,奇怪的错误:
Traceback (most recent call last):
File "python", line 16
print("Horray, you got it correct! +1 to you!")
^
SyntaxError: invalid syntax
总结一下,我需要知道'返回'声明正常 - 如果你有时间,请查看旧版本的代码。任何帮助,一如既往,将不胜感激!
答案 0 :(得分:0)
<强>错误:强>
print
语句缺少右括号return
在功能之外<强>代码:强>
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()