How to Find Square Root of a Number in Python?

Yo fam! We gonna learn the way to find the square root of a positive real number in Python. We shall use import, data types, and operators in Python. Precisely speaking, we use the exponent operator in Python.

Codevarsity
Coding Tutorials
2 min readJan 30, 2019

--

The square root of a number is a value that, when multiplied by itself, gives the number. In 4 x 4 = 16 , 4 is a square root of 9 . Also, note that (-4) x (-4) also equals to 9 . Hence -4 is also a square root of 16 . But, ‘’ always denotes a positive square root such as √9 is always equal to +3 .

Python Code

# Python Program to calculate the square root# Note: change this value for a different result
num = 25
# uncomment to take the input from the user
#num = float(input('Enter a number: '))
num_sqrt = num ** 0.5
print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))

Output

The square root of 25.000 is 5.000

Explanation

In the above program, we store the number in num and find the square root using the ** or the exponent operator. This program works for all positive real numbers. But for negative or complex numbers, please check it out here.

You can also check the similar article on ‘codevarsity.org

--

--