Getting value of a variable without changing the expression in Python

Peter Otten __peter__ at web.de
Thu May 21 08:57:11 EDT 2020


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]




More information about the Python-list mailing list