Find Square Root Without Using Sqrt In Python

Find Square Root Without Using Sqrt In Python | The square root of a number is a value that, when multiplied by itself, returns the original number. There are two square roots for every positive number. Positive and negative signs have the same value. For example:– √4 = ±2

The complex numbers are included in the square root of a negative number, but their explanation is outside the scope of this article. This article will show you how to calculate square root in python without math or sqrt function. We will use simple logic to achieve our expected output. Using the exponent operator, we will find the square root in python 3 without math. Have a look at the following examples:-

Example 1:
Number: 100
Square root: 10

Example 2: 
Number: 49
Square root: 7

Example 3: 
Number: 3.9
Square root: 1.9748417658131

Program to Find Square Root Without Using Sqrt In Python

Approach:

1. When the power of two is applied to any integer, the result is the square of such a number. Therefore we can use the power of 1/2 to calculate square root in python without sqrt.
2. To add the power to an integer, Python provides the exponential operator (**). 
3. Both number and power are accepted by this operator.
4. To get the square root of 25, for instance, use the code: 25 **0.5. 

Now, without using the sqrt technique, we can get the square root in Python. Here’s a little demonstration.

Example:

num = int(25)
power = 0.5
output = num ** power
print("The square root value is: ", output)

Output:-

The square root value is: 5.0

Find Square Root Without Using Sqrt In Python by taking Input from User

In the previous program, we took a number directly in the program. Let us see another program to find square root without using sqrt in Python by taking input from the end-user.

number = float(input("Enter a number: "))
exp = 0.5
result = number ** exp
print("The sqrt is: ", result)

Output:-

Enter a number: 81
The sqrt is: 9.0

Enter a number: 625
The sqrt is: 25.0

Enter a number: 64576254
The sqrt is: 8035.935166488092

This brings us to the end of the article. We saw a python program to find square roots without the math function. We used the power method and saw various test cases and examples. 

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *