def sqrt(a):
def tryit(x):
return 0.5 * (a/x + x)
return fixedPoint(tryit(x), 0.0001)
def sqrt(a): def tryit(x): return 0.5 * (a/x + x) return fixedPoint(tryit(x), 0.0001)
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are a couple of problems:
fixedPoint()– what’s that? Is this defined somewhere else?xin the function without having defined it.sqrt(), but the logic isn’t anywhere near something that would calculate the square root of anything.There is at least one inelegance:
tryit()). This is not a problem per se, but it doesn’t make much sense, and you’re relying on a local variableabeing defined here instead of passing that variable to a stand-alone function defined on the module level. It’s hard to tell what that function is supposed to be doing, though.tryit()isn’t a good function name.