To write a program to find the square root of a number.
- Hardware โ PCs
- Anaconda โ Python 3.7 Installation / Moodle-Code Runner
Define a function.
Assign number_iters = 100 in the function to perform 100 iteratios.
Calculate number = 0.5 * (number + a / number) for 100 iterations.
Return number
n=int(input())
a=0.5*n
b=0.5*(a+n/a)
while b!=a:
a=b
b=0.5*(a+n/a)
print("Square root of the number:",a)
Thus the program to find the square root for the given number(newton's method) using function is written and verified using python programming.