+ 2
How can i define a function in python to calculate the square root of a number?
4 Respuestas
+ 6
from math import sqrt
print (sqrt (100))
+ 5
def sq_rt(x):
return x**.5
+ 1
I would just add that there is no point in reinventing the wheel - just use math.sqrt() :)
0
First thing first, you must import module math.
So, the code may be like this :
import math
def calculate_square_root(x):
value=math.sqrt(x)
print (value)
calculate_square_root(36) #number in parentheses can be changed as you like