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