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


On 5/21/20 5:56 AM, 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?

Python, like most computer languages doesn't directly support that sort
of operation, one key point here is that in that context = means assign,
or change to, and implies that the name on the left takes on the value
to the right.

There may be a library somewhere that allows you to pass
"flowrate=veloctiy*area" (note, changed to a string) and the values for
flowrate and area and it solves for veloctiy.

Or a library where you do something like

def flowrate_fun(veloctiy):

??? return veloctiy*area

?veloctiy = solve(flowrate_fun, flowrate)


i.e. you pass a function and it finds what input make the function have
a give value.

-- 
Richard Damon