I have the following function, and PyCharm is alerting me on the elif statements about "simplify chained comparison". The code works and I am getting the object I want, just wondering about the warning and how I can make it better?
def preferred_contacts(self):
x = random.randint(0, 100)
email = u'E'
text = u'M'
phone = u'P'
letter = u'L'
none = u'N'
if x < 25:
return email
elif x >= 26 and x <= 50:
return text
elif x >= 51 and x <= 75:
return phone
elif x >= 76 and x <= 100:
return letter
else:
return none
x >=comparisons, since by virtue of reachingelifit's already been shown to not match the earlier conditions - mhlesterelif 76 <= x <= 100:would you what you expect it to do. - SylvainDandops either;elif 26 <= x <= 50and so on... - Drewnessnone, as you've boundedxat 100, and 100 will returnletter. - Silas Ray