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.
Valeurs (entrée)
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
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…
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.
thank you for your reply.
Is the amendment correct?
I have another error:
Avertissement:IronPythonEvaluator.EvaluateIronPythonScript l’opération a échoué.
Traceback (most recent call last):
File “”, line 40, in
IndexError: index out of range: 1
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
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#Les entrées effectuées dans ce noeud sont stockées sous forme de liste dans les variables IN.
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
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.