Simplified notation of condition if/else on python or function / expression

Hello Guys

made a simple code with the conditions, but it turns out that a lot of input and output data, because of this the code in python is very long, poorly readable and difficult to edit

Please tell me, is it possible to write down the condition if/else in python as easy as possible (in order not to create conditions for each case x and y), or how can it be otherwise that the data is written in the condition to be list?
Or maybe something different can all this be done?

if_else.gh (85.3 KB)

Yeah I think we can make some improvements here. Firstly though can you set out the logic you are trying to create? From a quick glance through, it seems to be if y=48 then l=85 and m=16 and as x increases, a increases. It then progresses with certain variables changes as the inputs do. Without digging through all 300 lines of your code and deciphering this for myself, can you set out the logic in a few lines on here?

1 Like

Matt_Harwood, thank you very much for the answer
the logic is simple. Now let us assume the first condition: if x = 100 and y = 48 then a = 25 m = 16 d = 85

and so we sort through all possible pairs of x and y values, and their corresponding a, m, l.

image

I can put pairs of values of x and y and the corresponding a, m, l into a list of data. but I don’t know how to register it later in python? or through function or expression?

Can I give a more simplified example?

1 Like

That is the logic behind one single operation, what I’m asking is what is the logic behind the entire operation? It can be deduced from the script, but at 300 lines that asking quite a lot of someone!

1 Like

Hello,

You could use a python dictionary as follows (here i have split it over multiple lines separated by commas:

aml_by_xy = {(100,48): (25,16,85),
             (120,48): (36,16,85),
             }
x = 100
y = 48
a, m, l = aml_by_xy[(x,y)]
print a
print m 
print l

25
16
85

This is easier to write, read and edit and will execute much more quickly. I am using tuple unpacking to get the a, m and l values out of the tuple (25, 16, 85)

3 Likes

There’s a lot for you to learn, but hopefully you can make sense of the attached. It gets the full function done around 30 lines as opposed to 300. I’ve tried to keep the logic simple, so have flattened the trees into lists, and only used lists/tuples.

if_else.gh (99.0 KB)

3 Likes

Matt_Harwood
Thank you very much rays of gratitude !!! I don’t know how to thank you !!!
Yes, you all correctly understood the logic !!!
Yes, I learn python in small steps !!!

1 Like

Dancergraham
Thank you very much!!!