Search code examples
pythonjupyter-lab

How to make the unit show up at the result after square root calculation using handcalcs and forallpeople Python libraries?


I am using forallpeople Python library within handcalcs Python library. After performing square root calculation, the unit is not showing up at the calculation result:

import handcalcs.render
from math import sqrt, pi
import forallpeople as si
si.environment('structural', top_level=True)

And here is the calculation:

%%render 1 short
A = (78.3*MPa)
B = (56.6*MPa)
C = (80.4*MPa)
D = sqrt(A**2 + B**2 + C**2)

And here is the output:

The output of the calculation

I wonder whether there is a way of making the unit show up, i.e. D = ... = 125.7 MPa


Solution

  • i use the sqrt() function from numpy this worked perfectly for me.

    from numpy import sqrt
    from handcalcs.render import render
    import forallpeople as si
    

    then just calculate as normal

    %%render 
    l=5*si.m
    b=10*si.m
    A= l*b
    A_sqrt= sqrt(A)
    

    Output is: Output