36
loading...
This website collects cookies to deliver better user experience
sqrt()
and pow()
functions, using which you can calculate the square root of a given number.sqrt()
function takes one parameter and returns the square root of the provided number. # Import math module
import math
# calculate square root of given number
print(math.sqrt(25))
# square root of 10
print(math.sqrt(10))
# square root of 0
print(math.sqrt(0))
# square root of decimal number
print(math.sqrt(4.5))
5.0
3.1622776601683795
0.0
2.1213203435596424
sqrt()
method can take only positive numbers in case if you provide the negative number you will get a ValueError as shown below.# Import math module
import math
# calculate square root of negative number
print(math.sqrt(-33))
Traceback (most recent call last):
File "c:\Projects\Tryouts\main.py", line 5, in <module>
print(math.sqrt(-33))
ValueError: math domain error
pow()
* method can be used to compute the square root of any number. This pow()
function takes two parameters and multiplies them to compute the results. This is done in order to the mathematical equation where, # Import math module
import math
# calculate square root of given number
print(math.pow(25,0.5))
# square root of 10
print(math.pow(10,0.5))
# square root of 0
print(math.pow(0,0.5))
# square root of decimal number
print(math.pow(4.5,0.5))
5.0
3.1622776601683795
0.0
2.1213203435596424