algorithmic modeling for Rhino
I have a question regarding writing multiple conditions in Python. I wanted to write a set of rules in Grasshopper Python that has a set of conditions. So, what I initially plan to do is for the code to go 'if A is True then go to B and if B is true then go to C and if all is true then the answer is X'. But in my current script, the codes are very repetitive and doesn't work that way. Do any of you know how to make this script more efficient? Thank you in advance. I would appreciate your help.
Python is not my thing, but considering the genericness of the problem, I would break up the logic thusly (in C#):
// Reject numeric cases.
if (a >= 10 || c != 0) return -0.4;
// Reject textual cases.
if (b != "Square" && b != "Circle") return -0.4;
// Handle final case.
if (d <= 1) return -0.5;
if (d == 2) return -0.3;
if (d >= 4) return -0.2;
I think the problem might be that all your 'and' and 'or' keywords are on the same level. It think you need to combine the two statements on either side of the 'or' operator into a single block, probably using precedence brackets.
Thank you for the reply. I have used your concept and it works well. Thank you very much for your help.