def sqrt(number):
number = root**2
return root
def area_triangle(a, b, c):
x = (a+b+c)/2
result = x*(x-a)*(x-b)*(x-c)
print (sqrt(result))
area_triangle(4,5,6)
This gives me a name error which "NameError: name 'root' is not defined"
I want to do this without math.sqrt orroot = number**(1/2)
How can I solve this without using these two and why doesn't the same error occurs as "NameError: name 'number' is not defined" if I use the alternative?
math.sqrt
or one-half power? I see two main reasons to avoid that:when you need more precision than the 15-17 significant digits thatmath.sqrt
and one-half power provide, or you are working with large integers and you want an exact answer for the integer part of the square root. Thedecimal
module handles the first case, and for the second case you can do a web search to find such a function.