I am starting to learn python and since I have had some programming before ( intro to java last semester and intro to c++ a couple years ago) the teacher gave me an interesting problem to solve. It is an equation called the Prandtl equation from fluid flow measurement it is 1/sqrt(f) = 2.0*log(Re*sqrt(f))-0.8 and the reason the Reynolds number needs to be above 4000 is because the flow must be turbulent for the Prandtl equation to apply to that system
I wrote a program that should(?) solve the equation relatively accurately but I can not get it to execute properly to find out if it works or not, the code is below and I am using pythonwin editor in my attempts to execute it
import math print "this program solves the prandtl equation by iteration" Re = input("please input the renolds number now") if Re<4000: print "not a valid entry" else: for i in range(1,11): f= 0.054 A = 1/sqrt(f) B = 2.0*log(Re*sqrt(f))-0.8 if A<B: f = f-((f-0.008)/2) i = i+1 elif B>A: f= f+((0.1-f)/2) i = i+1 else: break print "the friction factor is",f
the program will execute through accepting the Reynolds number but then it stops an error msg that says that sqrt is not defined since I imported the math library I am not sure what that is about
any ideas on what I am doing wrong?