• anonymous
In Lecture 4, the professor says that even without his explanation, we should be able to understand this code (see below). Unfortunately that is not the case so far. I can't get it to do anything when I run it in IDLE. Can anyone help me figure out how to make sense of it? I copied this directly from the file "Lec04.py" def findRoot(pwr, val, epsilon): """assumes pwr an int; val, epsilon floats pwr and epsilon > 0 if it exists, returns a value within epsilon of val**pwr otherwise returns None""" assert type(pwr) == int and type(val) == float\ and type(epsilon) == float assert pwr > 0 and epsilon > 0 if isEven(pwr) and val < 0: return None low = -abs(val) high = max(abs(val), 1.0) ans = (high + low)/2.0 while not withinEpsilon(ans**pwr, val, epsilon): #print 'ans =', ans, 'low =', low, 'high =', high if ans**pwr < val: low = ans else: high = ans ans = (high + low)/2.0 return ans
MIT 6.00 Intro Computer Science (OCW)
• Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Looking for something else?

Not the answer you are looking for? Search for more explanations.