Python Program – How to Find the Square Root of Any Number?

In this Python example series, we will cover the program to find the square root of any given number

1. What is Square Root of a Number?

Square root of a number is a value, which on multiplication by itself gives the original number. 

Examples:

squareRoot(16) = 4
squareRoot(25) = 5
squareRoot(36) = 6
squareRoot(49) = 7

In python, we can calculate the square root of any number in different ways. Let’s implement each of them using different methods.

Some of the topics which will be helpful for understanding the program implementation better are:


2. Square Root of a Number using Power Method

Let’s find out the implementation of the program for finding the square.

#Sqrt of any number
num1 = float(input("Enter the number: "))

sqrt_res = num1**0.5
print("The Square root value is: ", sqrt_res)
Output
Enter the number: 34
The Square root value is:  5.8309519

Let’s use the power function from the math module and see the implementation below

#Sqrt of any number
import math
num1 = float(input("Enter the number: "))

sqrt_res = math.pow(num1, 0.5)
print("The Square root value is: ", sqrt_res)
Output
Enter the number: 25
The Square root value is: 5.0

3. Square Root of Any Number using math Module in Python

The math module contains different functions, one of them is sqrt function. Let’s see the same above program implementation.

#Sqrt of any number
import math
num1 = int(input("Enter the number: "))

print(math.sqrt(num1))
Output
Enter the number: 25
5.0

4. Conclusion

In this article, we discussed how to find the square root of any number using the math module and power method.


Helpful Links

Please follow the Python tutorial series or the menu in the sidebar for the complete tutorial series.

Also for examples in Python and practice please refer to Python Examples.

Complete code samples are present on Github project.

Recommended Books


An investment in knowledge always pays the best interest. I hope you like the tutorial. Do come back for more because learning paves way for a better understanding

Do not forget to share and Subscribe.

Happy coding!! ?

Recommended -

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Index