# Python Program to find the square root of a number by Newton’s Method

0 like 0 dislike
43.9k views

Python Program to find the square root of a number by Newton’s Method

0 like 0 dislike
by Goeduhub's Expert (5.8k points)
edited

Newton's Method to find Square root

Let the given number be b and let x be a rough guess of the square root of b.

New x = 0.5 * (x + b/x)

Program Code

def newton_method(number, number_iters = 100):

a = float(number)

for i in range(number_iters):

number = 0.5 * (number + a / number)

return number

a=int(input("Enter first number:"))

b=int(input("Enter second number:"))

print("Square root of first number:",newton_method(a))

print("Square root of second number:",newton_method(b))

Output

Enter first number:81
Enter second number:5
Square root of first number: 9.0
Square root of second number: 2.23606797749979

## For more RGPV/UTMP CSE V Sem Python Lab Experiments Click here

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.