使用教科书和代码课程学习Python。
此代码返回SyntaxError。我不能在同一elif语句中使用两个大于/小于符号吗?还是我的问题<< ='?
def movie_rating(rating):
if rating <= 5:
return "Avoid"
elif rating > 5 and <= 9:
return "I recommend!"
else:
return "Amazing"
答案 0 :(得分:0)
The problem is because of your and
in line 4, this error happening because when you use and you need to define a new condition in other word you should change your code to one of this codes:
def movie_rating(rating):
if rating <= 5:
return "Avoid"
elif rating > 5 and rating <= 9:
return "I recommend!"
else:
return "Amazing"
or change your code to this:
def movie_rating(rating):
if rating <= 5:
return "Avoid"
elif 5> rating <= 9:
return "I recommend!"
else:
return "Amazing"
if you want to know how you can use and
in python, follow this link:
How to use boolean 'and' in Python and how use if and else elif or