【发布时间】:2016-09-04 14:36:47
【问题描述】:
我在使用 Python 2.7 编写的这段代码时遇到了一些问题。它在 elif 语句上给了我一个语法错误,但是没有解释,我在代码中找不到任何合理的错误。 (typeline是我定义的一种方法。)
num = randrange(-25,15)
""" Toxic """
if num >= -25 and num < -10:
responses = ["Ugh, nasty.", "That was absolutely disgusting.", "My stomach feels like it's going to explode.", "Pardon me if I puke."]
typeline(responses[randrange(0,4)], "jack")
return [num, "Jack ate a VERY TOXIC FRUIT and survived.", "Jack ate a VERY TOXIC FRUIT and died."]
""" Mildly poisonous """
elif num >= -10 and num < 0: """ SYNTAX ERROR HERE """
responses = ["Yuck", "It's kinda bitter.", "Tastes like an unripe banana.", "It's not so bad."]
typeline(responses[randrange(0,4)], "jack")
return [num, "Jack ate a MILDLY TOXIC FRUIT and survived.", "Jack ate a MILDLY TOXIC FRUIT and died."]
""" Healthy """
else:
responses = ["Definitely not too bad", "It's almost kind of tasty!", "Should I make a jam out of this?", "This is my new favorite fruit."]
typeline(responses[randrange(0,4)], "jack")
return [num, "Jack ate a HEALTHY FRUIT and was rescued.", "Jack ate HEALTHY FRUIT and survived."]
错误:
File "<stdin>", line 9
elif num >= -10 and num < 0:
^
SyntaxError: invalid syntax
【问题讨论】:
-
请添加运行时看到的错误信息。
标签: python python-2.7 if-statement syntax-error