# Need help with Python

Need help with Python
Hello,
I am ignorant in Python, and I would have to program a node
Can you help me
Values are numbers.

X1 (list), Y1 (list), E (list), M (an integer)
Values (output)
X2 (list), Y2 (list), L (list)
Formulas:
If X1 = E
Then
X2 = X1
Y2 = Y1 + M
L = Y2
Else
X2 = X1 + M
Y2 = Y1
L = X2
End
*************** French
Besoins dâ€™aide en Python
Bonjour,
Je suis ignorant en Python, et jâ€™aurais pesoins de programmer un nĹ“ud
Pouvez-vous mâ€™aider
Les valeurs sont des nombres.
X1 (list) , Y1 (list) , E (list) , M (un nombre entier)
Valeurs (sortie)
X2 (list) , Y2 (list) , L (list)
Formules :
If X1 = E
Then
X2= X1
Y2= Y1 + M
L= Y2
Else
X2= X1 +M
Y2=Y1
L=X2
Fin

Get started then come back when you get stuck. There are many examples on this forum you can follow, plus stack overflow, the Dynamo primer, python.org etc etc. Autodidacts reign supreme.

Ps. Youâ€™ve practically written the script in python, you just need to format it

2 Likes

Thank you for this answer which will not make much progress for me â€¦

http://dynamoprimer.com/en/09_Custom-Nodes/9-4_Python.html
And here is the way to present a code into forum posts:

Courage!

Hello,

Itâ€™s not the courage thatâ€™s missing, but the time â€¦

The big problem for me is the translation with google! (Although I found links in france for python).

Learning Python shouldnâ€™t be a problem but this forum is not the place for it. But you will find good examples such as this one:
http://dynamobim.org/forums/topic/if-then-else-in-dynamo/
You can then paste your code here to get further advice from expertsâ€¦

If time is the problem and Dynamo is un-chartered territory for you, then its clearly the wrong tool for the job.

Unfortunately learning is nothing but time consuming Iâ€™m afraid and as much of an investment as you make it.

Like @Yna_Db said, this is not a Python forum. However, weâ€™re happy to help you out when you are stuck, but first you have to give it a go. The reply from @Thomas_Mahon earlier was actually encouraging you to do just this, your psuedocode is pretty close so converting to Python isnâ€™t that hard, so give it a go and then come back after you have and we can help point out where itâ€™s going wrong.

Cheers,
Dan

Hello,

One test but does not function line 40

1 Like

Hi @Alain_Hamel ,
youâ€™re missing an indent on lines 40 and 43 (because youâ€™re inside a loop).

1 Like

Is the amendment correct?
I have another error:
Traceback (most recent call last):
File â€śâ€ť, line 40, in
IndexError: index out of range: 1

Like that?

code 1.py (975 Bytes)

Like this

1 Like

You had an issue line 21 :

appending IN[2] to a list adds the whole list as a nested list. The length of that list will be 1. I just changed thatâ€¦

``````import clr
from Autodesk.DesignScript.Geometry import *
dataEnteringNode = IN

#The inputs to this node will be stored as a list in the IN variable.
A = IN[0]
B = IN[1]
E = IN[2]
M = IN[3]

listX1 = []
listY1 = []

listX2 = []
listY2 = []

listE = []

listE  = E

#convert lists
if hasattr(A, '__iter__'):
for i in range(0,len(A)):
listX1.append(A[i])
else:
listX1.append(A)

if hasattr(B, '__iter__'):
for i in range(0,len(B)):
listY1.append(B[i])
else:
listY1.append(B)

# matched lists
lists = []

for i in range(0,len(listX1)):
if listX1[i] == listE[i]:
listX2.append(listX1[i])
listY2.append(listY1[i]+M)
else:
listY2.append(listX1[i])
listX2.append(listY1[i]+M)

lists.append(listX2)
lists.append(listY2)

#Assign your output to the OUT variable
OUT = lists``````
1 Like

This is just a tabulation problem?

Iâ€™ll finish the code

My pleasure

you had the tabulation problem on line 41 and 43 at first.
The other issue was the way you defined listE :
`listE.append(E)` is different from `listE = E`.

Yes, I just wanted to mimic the list code X1.append (A)

thank you,
The completed code:

2 Likes

I understand. If you had mimicked it all the way it would have also worked:

``````   if hasattr(E, '__iter__'):
for i in range(0,len(E)):
listE.append(E[i])
else:
listE.append(E)
``````

This part checks whether E is a list :

``````   if hasattr(E, '__iter__'):
``````

if it is then it appends each element of the list to listE one by one.
if E is a single element and not a list, it will be appended to listE.

Anyway congrats on your first python code! !!