# Same code Python with a different result in dynamo and pythontutor

**URL:** <https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088>\
**Category:** Revit\
**Tags:** dynamo\
**Created:** [May 16, 2019, 11:45pm UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088 "2019-05-16T23:45:47Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![joaoluiz.sribeiro](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@joaoluiz.sribeiro](https://forum.dynamobim.com/u/joaoluiz.sribeiro)\
**Post date:** [May 16, 2019, 11:45pm UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/1 "2019-05-16T23:45:47Z")

</div>

Hi Guys,

I wrote a code in phyton and work perfectly in one platform call pythontutor(to learn python), but when I put the code in dynamo, he not work so well and show me other results,  
Does someone know the problem??

pythontutor:

 ![Capturar](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/9/c967afe8595bf38ab40f88f8ef8352a846baf5dc.png)  
Dynamo:  
 ![Capturar2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/6/064a6a42d3fa3005fdd2e882f340cde2a1a0b426.png)

The script:

```
from math import sqrt
    Q = [[0.25,0.25,0.25,0.25,0.16,0.16],[0.25,0.25,0.25,0.25,0.19,0.16]]
    D = [[21.6,21.6,21.6,17,17,1],[21.6,21.6,21.6,17,17,17]]
    B = [17,21.6,27.8,35.2,44,53.4,66.6,97.8] #List Base.
    def recalculate(a,b):
        V = 4000*a/(b*b*3.1415)
        Vaz = 14*sqrt((b/1000))
        if V < 3 and V< Vaz:
            return False
        else:
            return True
    for i, list in enumerate(Q):
        for j, number in enumerate(list):
            a=recalculate(number, D[i][j])
            if a==False: 
                print("OK")
            else:
                print("Recalculate")
                aux=0
                while True:
                    b=recalculate(number, B[aux])
                    if b==False:
                        break
                    else:
                        aux+=1
                D[i][j]=B[aux]
    OUT = D
```

---

<div class="post-metadata">

**Author:** ![architectcoding](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/architectcoding/32/105118_2.png) [@architectcoding](https://forum.dynamobim.com/u/architectcoding)\
**Post date:** [May 16, 2019, 11:57pm UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/2 "2019-05-16T23:57:42Z")

</div>

There are no print statements in Python scripts inside Dynamo. You will have to use the append method to add what is inside the print statement to a list and output it.

---

<div class="post-metadata">

**Author:** ![joaoluiz.sribeiro](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@joaoluiz.sribeiro](https://forum.dynamobim.com/u/joaoluiz.sribeiro)\
**Post date:** [May 17, 2019, 2:46am UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/3 "2019-05-17T02:46:02Z")

</div>

I’m really don’t know what to do… =(  
I do my best in that script and he don’t work…T.T

 ![Sem%20t%C3%ADtulo](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/d/5da305540db567a1a06a86b98344a93957e0a31d.png)

---

<div class="post-metadata">

**Author:** ![architectcoding](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/architectcoding/32/105118_2.png) [@architectcoding](https://forum.dynamobim.com/u/architectcoding)\
**Post date:** [May 17, 2019, 3:13am UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/4 "2019-05-17T03:13:38Z")

</div>

Don’t despair, will gladly walk you through it. But can you upload the code preformatted please?

```
for el in listOne:
    print("I like preformatted text")

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/d/ed3b0172c371cdb3e0de3a0f315162d83ec496d6.png)

It will save me some time. Thanks!

---

<div class="post-metadata">

**Author:** ![joaoluiz.sribeiro](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@joaoluiz.sribeiro](https://forum.dynamobim.com/u/joaoluiz.sribeiro)\
**Post date:** [May 17, 2019, 3:29am UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/5 "2019-05-17T03:29:51Z")

</div>

[Test.dyn](https://forum.dynamobim.com/uploads/short-url/zsxf6UGF0Tr9hHV5GHQY1Njva76.dyn) (6.5 KB)

```
# Ativar suporte de Python e carregar biblioteca DesignScript
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
from math import sqrt

Q = IN[0]
D = IN[1]
B = [17,21.6,27.8,35.2,44,53.4,66.6,97.8] #List Base.

def recalculate(a,b):
    V = 4000*a/(b*b*3.1415)
    Vaz = 14*sqrt((b/1000))
    Console(context=locals())
    if V < 3 and V< Vaz:
        return False
    else:
        return True
        
for i, list in enumerate(Q):
    for j, number in enumerate(list):
        a=recalculate(number, D[i][j])
        if a==False: 
			break
        else:
            aux=0
            while True:
                b=recalculate(number, B[aux])
                if b==False:
                    break
                else:
                    aux += 1
            D[i][j]=B[aux]
            
# Atribua a sua saída para a variável OUT.
OUT = D[i][j]
```

---

<div class="post-metadata">

**Author:** ![architectcoding](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/architectcoding/32/105118_2.png) [@architectcoding](https://forum.dynamobim.com/u/architectcoding)\
**Post date:** [May 17, 2019, 4:51am UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/6 "2019-05-17T04:51:31Z")

</div>

Hi @joaoluiz.sribeiro,

took a look into your code, but can you elaborate a bit what’s your end goal? I mean, the kind of operation that is going or how is the process to get to the result dat you want?

Thanks!

---

<div class="post-metadata">

**Author:** ![joaoluiz.sribeiro](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@joaoluiz.sribeiro](https://forum.dynamobim.com/u/joaoluiz.sribeiro)\
**Post date:** [May 17, 2019, 5:34am UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/7 "2019-05-17T05:34:15Z")

</div>

We have two list Q and D.  
In the script after you make these two formulas (V = 4000_Q/D_D_3.1415)) and (Vaz = 14_sqrt((D/1000))),we will obtain 2 new lists (V and Vaz).We will need to meet these two conditions: V \< 3 and V \< Vaz.  
If these conditions were accepted, the final result is the list D. But if you don’t satisfy one condition, you will need to replace the item how not pass in list D to one item in List B, you will try each number until satisfies these two conditions(V\< 3 and V\<Vaz),so the final result, in that case, is a new list D with the element who was replaced by the number in list B.  
Do you understand? =)

---

<div class="post-metadata">

**Author:** ![lucas\_20](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@lucas\_20](https://forum.dynamobim.com/u/lucas_20)\
**Post date:** [May 17, 2019, 12:19pm UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/8 "2019-05-17T12:19:22Z")

</div>

Hi @ joaoluiz.sribeiro,

It explains me better the purpose of this code there. From the formulas used, it seems that you are trying to calculate something about the flow regime in closed conduits, but it is not very clear. Explain better what should be done by the code.

Translated by admin. Original text below.

* * *

Oi @joaoluiz.sribeiro,

Me explica melhor o objetivo desse código ai. Pelas formulas usadas, parece que você tá tentando calcular algo sobre regime de escoamento em condutos fechados, mas não tá bem claro. Explique melhor o que deve ser feito pelo código.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [May 17, 2019, 1:28pm UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/9 "2019-05-17T13:28:38Z")

</div>

@lucas_20, the official forum language is English. This is a requirement for search to work. Please keep all posts to English in the future, or post both the translation and your original text similar to above.

---

<div class="post-metadata">

**Author:** ![lucas\_20](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@lucas\_20](https://forum.dynamobim.com/u/lucas_20)\
**Post date:** [May 17, 2019, 2:07pm UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/10 "2019-05-17T14:07:48Z")

</div>

sorry, I just tried to understand better the problem because he seems to have some difficuties to express in english

---

<div class="post-metadata">

**Author:** ![architectcoding](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/architectcoding/32/105118_2.png) [@architectcoding](https://forum.dynamobim.com/u/architectcoding)\
**Post date:** [May 19, 2019, 12:21pm UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/11 "2019-05-19T12:21:01Z")

</div>

Sorry joao, was trying to understand your explanation. I think you explanaided quite well, the problem is that, I think, there are too many variables and its taking data from many lists. Can you elaborate something graphic? Or just point me how you obtain the two first values with formulas.  
Thanks!

---

<div class="post-metadata">

**Author:** ![joaoluiz.sribeiro](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@joaoluiz.sribeiro](https://forum.dynamobim.com/u/joaoluiz.sribeiro)\
**Post date:** [May 20, 2019, 2:06am UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/12 "2019-05-20T02:06:24Z")

</div>

Guysss!!! =D  
After 2 days debugging that shit, I have finally found the problem!!! =D  
I have changed a lot the script to work.  
the principal problem is when an applied division in python inside the Revit, he doesn’t interpret the number after the dot. (confusing)  
Example:  
**17/100 = 0**  
**17/100.00 = 0.17**  
The second problem is one in the input (KKK =D), but I found easily.

Thanks for help =)!  
@architectcoding  
@lucas_20  
@jacob.small

P.S: Yeah man! I create a script that calculates and design in Revit the water pipes. (NBR 5626)  
The script creates a schedule with information of design, he changes the colors and overrides the size of pipes with problems.  
Pic:

 ![Capturar](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/c/7c94c4400c9be1a79c62db222b347e777cfeeeab.png)

 ![Capturar3](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/f/ef075f6af9e68b63a332b3a3666db305fffb2412.png)

---

<div class="post-metadata">

**Author:** ![architectcoding](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/architectcoding/32/105118_2.png) [@architectcoding](https://forum.dynamobim.com/u/architectcoding)\
**Post date:** [May 20, 2019, 2:28am UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/13 "2019-05-20T02:28:07Z")

</div>

Congratulations Joao! Amazing job you have done!  
Well, here is the explanation for your first problem:

> <https://stackoverflow.com/questions/21316968/division-in-python-2-7-and-3-3/21317109#21317109>

Congrats again!

---

<div class="post-metadata">

**Author:** ![vitorguilhermer](https://avatars.discourse-cdn.com/v4/letter/v/e0b2c6/32.png) [@vitorguilhermer](https://forum.dynamobim.com/u/vitorguilhermer)\
**Post date:** [April 24, 2020, 11:52am UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/15 "2020-04-24T11:52:34Z")

</div>

Congratulations, How this routine works? you sell

---

<div class="post-metadata">

**Author:** ![joaoluiz.sribeiro](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@joaoluiz.sribeiro](https://forum.dynamobim.com/u/joaoluiz.sribeiro)\
**Post date:** [April 27, 2020, 2:10am UTC](https://forum.dynamobim.com/t/same-code-python-with-a-different-result-in-dynamo-and-pythontutor/36088/16 "2020-04-27T02:10:15Z")

</div>

Sorry,no…
