I have this (working) piece of python code, whose purpose is to return a string (actually a Bootstrap button label) depending on a 7-condition set:
....
if cond1:
if cond2:
if cond3:
...
return string10
else:
...
return string11
else:
if cond4:
if cond5:
...
return string9
else:
if cond6:
...
return string7
else:
...
return string8
else:
if cond7:
...
return string6
else:
if cond6:
...
return string5
else:
if cond3:
...
return string3
else:
...
return string4
else:
if cond2:
...
return string1
else:
...
return string2
I know this is horrible, and also difficult to maintain. My question is, how to improve it?
One thing I tried was to ‘linearize’ and get rid of the tree-like path, and having instead:
CompositeCond1=(mess made with and's and or's on cond1--cond7)
...
CompositeCond11=(mess made with and's and or's on cond1--cond7)
if CompositeCond1:
...
return string1
(more of this...)
if CompositeCond11:
...
return string11
but it seems little help, and I am not sure I like it more.
Any other ideas? Thank you!