osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting value of a variable without changing the expression in Python


ansari.aafaq1994 at gmail.com wrote:

> Lets say i have a expression:
> flowrate=(veloctiy*area)
> i can find the flowrate with this expression
> but if i dont wanna change the expression and want to find the velocity by
> giving it value of area and flowrate ,how do i do this in python? is there
> any library or package or module for this?

With sympy 

ttps://docs.sympy.org/latest/tutorial/intro.html

you can write:

>>> import sympy
>>> f, v, a = sympy.symbols("flowrate velocity area")
>>> sympy.solve(v*a - f, a)
[flowrate/velocity]
>>> sympy.solve(v*a - f, f)
[area*velocity]