+ 2

How can i define a function in python to calculate the square root of a number?

15th Jun 2017, 10:15 AM
Vikas Yadav
Vikas Yadav - avatar
4 Respuestas
+ 6
from math import sqrt print (sqrt (100))
15th Jun 2017, 11:25 AM
Sri Lakshmi
Sri Lakshmi - avatar
+ 5
def sq_rt(x): return x**.5
15th Jun 2017, 11:25 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
I would just add that there is no point in reinventing the wheel - just use math.sqrt() :)
15th Jun 2017, 10:37 AM
Bogdan Sass
Bogdan Sass - avatar
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
15th Jun 2017, 10:22 AM
Prima Akbar Mashudi
Prima Akbar Mashudi - avatar