语法错误:预期为“:”

SyntaxError: expected ':'

提问人:Z.r M 提问时间:5/7/2023 最后编辑:Karl KnechtelZ.r M 更新时间:9/15/2023 访问量:9554

问:

我该怎么办?

我给出了这个错误:

mylist=input('please inter your condition :')
If mylist == '10' or '9' or '8':
   print('well')
   print('well done')
else if mylist == '7' or'6' or '5' or '4' or '3':
   print('mid') 
   print('moderate') 
else if mylist == '2'   or '1':
   print('weak')
else print('0')  

 File "<ipython-input-42-fc470037cf12>", line 5
    else if mylist == '7' or'6' or '5' or '4' or '3':
         ^
SyntaxError: expected ':'

我在 : 和 ' 之间更改空格 但。。。。 伊伊应该怎么做?

python-3.x 语法错误

评论

1赞 Norio Yamamoto 5/7/2023
在提出问题之前,您必须参加巡回演出
1赞 sbottingota 5/9/2023
你不需要.这就是 python 的工作方式。elif:else if:
0赞 Karl Knechtel 9/15/2023
这回答了你的问题吗?“else if”的正确语法是什么?
0赞 Karl Knechtel 9/15/2023
除了抱怨的内容之外,此代码还有很多问题。

答:

-1赞 Maxime Baker 5/7/2023 #1

在 Python 中,有三种形式的 if...else 语句:

if 语句

如果。。。else 语句

如果。。。伊利夫...else 语句