Python script working in Dynamo - Help!

Hi all.

I have a section of python script that I am able to use on my pc ( with anoconda jupyter system).

But I’m unable to make the small changes necessary to get it to function the same way in dynamo can anyone help me? I’m sure it is quite simple for those of you that understand the interface far better than me.

Here is the unedited code. I know I need to change the input to the in[0] but im struggling to get the output to work.

from itertools import combinations_with_replacement
def find_sum_in_list(numbers, target):
    results = []
    for x in range(len(numbers)):
        results.extend(
            [  
                combo for combo in combinations_with_replacement(numbers ,x)  
                    if sum(combo) == target
            ]  
        )  
    optimalpanels = list(min(results, key=len))
    for i in range(len(optimalpanels)):
        if optimalpanels[i] == 172.00:
            optimalpanels[i] = 1
        if optimalpanels[i] == 215.00:
            optimalpanels[i] = 2
        if optimalpanels[i] == 225.00:
            optimalpanels[i] = 3
        if optimalpanels[i] == 235.00:
            optimalpanels[i] = 4
        if optimalpanels[i] == 337.5:
            optimalpanels[i] = 5
        if optimalpanels[i] == 450.00:
            optimalpanels[i] = 6
        if optimalpanels[i] == 562.50:
            optimalpanels[i] = 7
        if optimalpanels[i] == 675.00:
            optimalpanels[i] = 8
        if optimalpanels[i] == 787.50:
            optimalpanels[i] = 9
        if optimalpanels[i] == 900.00:
            optimalpanels[i] = 10
        if optimalpanels[i] == 1012.50:
            optimalpanels[i] = 11
        if optimalpanels[i] == 1125.00:
            optimalpanels[i] = 12
    print(optimalpanels)
    
x = float(input("Enter required length of wall:"))
inp = x 
find_sum_in_list([172.00 ,
215.00 ,
225.00 ,
235.00 ,
337.50 ,
450.00 ,
562.50 ,
675.00 ,
787.50 ,
900.00 ,
1012.50,
1125.00], inp)

Here is a screenshot of my dynamo

Here is the screenshot, of the code online with the output im looking for.

x = float(IN[0])

thanks!

Do you also know how to make the OUT= the find_sum_in_list. Thats what I’m struggling with now

I think you need to set OUT= the find_sum_in_list([…etc.],inp) on line 42

1 Like

You need to use return instead of print.

2 Likes

This solved the output element.

Thanks!