How to create recursive systems in Python

Hi everyone!

I am trying to create a python script in grasshopper where I have the following inputs:

1-Total Building Floors Area (m2)
2-TargetValue (m2)
3-Building1 (amount of floor)
4-Building2 (amount of floor)

and two outputs:
1-newBuilding1 (new amount of floor)
2-newBuilding2 (new amount of floor)

The idea is to set a target value (m2) and if the existing total building floor area is lower than the target value adding more floors to the building until the existing total building floor area reaches/passes the target value.

in a simpler way:

if TotalBuildableArea < TargetValue:
…newBuilding1 = Building1 + n
…n = {0,1,…∞}
…print newBuilding1

you can find the anticipated result in the attachments

I do understand the concept but have no idea about the coding part, if anyone has an experience and shares it with me I would be glad, thanks in advance.

I am pretty sure, everyone is capable of how to use google, the idea of the forum is to ask people’s opinions, not to be exposed shitty comments. The question can be very easy for a coder but I am an architect with no coding background. if you don’t want to help why do you waste your time here. This is just sad.

Yes it is.

I think you do not need recursion for this, just a simple while loop. For example:

area = 0
target_area = 10000

while area<target_area:
     floor_area = addfloor() #your floor adding code that returns floor_area
     area+= floor_area

Why do you bother to answer @ugur.yildirim.simsek 2 times without adding anything constructive to the discussion?
This community is build by people trying to help each other out, referring to a google search is in my opinion belittling and I see no place for that here.

There is no such thing as a stupid question only stupid answers…pick yours


@ugur.yildirim.simsek I hope someone else can anser your question as I’m not able to help you with it at the moment, but I did feel the need to write the above.


Ugur, It helps to provide more information in a complex post like this so people don’t have to recreate your data. Thanks