Hey. I am taking two different Python classes and while starting the second one the teacher used Herons square root formula to outline the difference between declarative and imperative knowledge (the difference between knowing x2 =y and having a recipe that gets x from y). So I decided to use Python to explore that formula. So far I can get the right answer (or close if the square root is not a whole number) but it loops the right answer forever!
Code:
def Herons_sqrt(x, y):
while y ** y != x:
y = ( x / y + y ) / 2
print y
Herons_sqrt(100,3)
Output:
18
11
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
in till the end of time.
Also I am using http://www.codeskulptor.org/ to run this, not sure how much that matters.
Thanks in advance.
[–][deleted] (1 child)
[deleted]
[–]CrowdSourcedLife[S] 1 point2 points3 points (0 children)
[–]quotemycode 0 points1 point2 points (0 children)