find square root of any number in python

In this example, we will find square root using three different methods.

Python Program to Square Root Using Exponent

An exponent is a number or letter written above and to the right of a mathematical expression called the base. It indicates that the base is to be raised to a certain power. x is the base and n is the exponent or power.

Example :

    
# Python 3 program to find square root using exponent.

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

#calculation of square root
sqrt = number ** 0.5

print("Square root:", sqrt)

    

Output :

    
Enter a number: 10
Square root: 3.1622776601683795
    

Python Program to Square Root Using math.sqrt() Method

sqrt() is the predefined method used to find square root in python. But we have to import math module to use the sqrt() method.

Example

    
#Import Module
import math

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

#Calucation of square root using math.sqrt() function
sqrt = math.sqrt(number)
print("Square root:" , sqrt)
    

Output :

    
Enter a number:10
Square root: 3.1622776601683795
    

Python Program to Square Root Using math.pow() Method

pow() is also a predefined method to find out power of a number, it takes two arguments as input, first is the number itself and second one is power of that number. The program is same as first program where we’re using (**) sign to find out the square root but only different is this that here we’re using a predefined method pow() instead of (**) sign to get the power of that number.

Example :

    
#Import Module
import math
number = int(input("Enter a number:"))

#Calucation of sqaure root using math.pow() function
sqrt = math.pow(number, 0.5)
print("Square root:" , sqrt)
    

Output :

    
Enter a number:100
Square root: 10.0
    

Share your thoughts

Ask anything about this examples