There are multiple approximations of the Colebrook equation. See here Which one are you referring to? It helps to know what you are trying to do more specifically.
Aside from that, there is an easy issue here.
1/math.sqrt(friction)=-2*math.log10((((eD/3.7)+(2.51/Re))*(1.14-2*math.log10(((eD/2)+(21.25/Re**0.9))))))
In Python (and most languages I've ever used), you can't write equations this way. The computer will not solve algebra for you. If you solve to get f=SomeEquation()
, only then can the computer actually do the math for you.
In your second example there are also issues.
import math
def friction(Re, eD):
eD= 0.0009
Re= 2300
f = -2*math.log10((((eD/3.7)+(2.51/Re))*(1.14-2*math.log10(((eD/2)+(21.25/Re**0.9))))))
return 1/math.sqrt(f)
You have defined a function which takes Re
and eD
, but then you immediately redefine them in thee function. There is a way to set a default value for these variables if you choose not to pass them in, but I don't think that's what you are trying to do here. Furthermore, (and you may very well have just left this part out for the sake of brevity) you never actually called your function, which means your script never actually does anything.
You need something like (and I'm not checking your equation here because I don't know which one you were going for):
import math
# Function definition
def friction(Re, eD):
f = -2*math.log10((((eD/3.7)+(2.51/Re))*(1.14-2*math.log10(((eD/2)+(21.25/Re**0.9))))))
return 1/math.sqrt(f)
# Call your function with your desired values (arguments) and store the result in f
f = friction(2300, 0.0009)
Hope that helped.