Consider the snippet
def check_conditions(range_of_numbers):
list1 = []
if condition1:
list1.append("message1")
if condition2:
list1.append("message2")
if condition3:
list1.append("message3")
try:
for i in range_of_numbers:
int(i)
except ValueError:
list1.append("message4")
return message
I want to have a list in the with messages only if the conditions were satisfied. I do not use multiple if's since it adds on to the code complexity and every time a new parameter is added I would end up adding a new if condition.
Aucun commentaire:
Enregistrer un commentaire