Find the Square Root in Python

A square root is the number that, when multiplied by itself, gives the original number. The square root of four is two because two x two equals four.

For example, the square root of 4 is 2 because 2*2=4.

Here Are Some Different Methods to Find the Square Root in Python

Python Program to calculate the square root using Exponent

# Python Program to calculate the square root using Exponent

# we are taking a number from user as input
# entered value will be converted to int from string
num = int(input("enter a number: "))

# we are using  exponent (**) sign
sqrt = num ** 0.5
print("square root:", sqrt)

Output

enter a number: 16
square root: 4.0

Python Program to calculate the square root using math.sqrt() Method

# Python Program to calculate the square root using math.sqrt() Method

# importing math module here
import math

# take input number from user & convert into integer
num = int(input("enter a number:"))

sqrt = math.sqrt(num)
print("square root:" , sqrt)

Output

enter a number: 16
square root: 4.0

Python Program to calculate the square root using math.pow() Method

# Python Program to calculate the square root using math.pow() Method

# importing math module here
import math

# take input number from user & convert into integer
num = int(input("enter a number:"))

#using a predefined method pow()
sqrt = math.pow(number, 0.5)
print("square root:" , sqrt)

Output

enter a number: 16
square root: 4.0

About The Author