You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Implement the square root function using Newton's method. In this case, Newton's method is to approximate sqrt(x) by picking a starting point z and then repeating z_next = z - ((z*z - x) / (2 * z))
4
+
# To begin with, just repeat that calculation 10 times and see how close you get to the answer for various values (1, 2, 3, ...). Next, change the loop condition to stop once the value has stopped changing (or only changes by a very small delta). How close are you to the math.sqrt value?
5
+
6
+
# Logic
7
+
# x is the number you want to find the sqrt of
8
+
# z is a guess at what the sqrt is?
9
+
10
+
importmath
11
+
12
+
x=float(input("Enter a number: "))
13
+
z=float(input("Sqrt guess: "))
14
+
15
+
print("Math.sqrt(x): "+str(math.sqrt(x))) # Accurate sqrt
0 commit comments