-3
我在第6年,我正在编写一个Python测验(只是为了好玩),而且我陷入了一个主要问题。 '返回声明不起作用。 这是我当前的代码:如何在Python中正确使用'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()
和我收到此错误:
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
综上所述,我需要知道“return”语句是如何工作的 - 正常 - 如果你有时间,请看看旧版本的我的代码。任何帮助,一如既往,将不胜感激!
的In y我们的'while'循环,你的第二个'print'缺少一个右括号')'。 – zondo
'return'没有正确缩进 –
另外,'(points) - 1'什么都不做。你必须'points - = 1' – Li357