Can someone please answer my question? Why am I getting the error message "TypeError: unsupported operand type(s) for ** or pow(): 'NoneType' and 'int'", when I run the following code?
import math
def distance (x1,y1,x2,y2):
horizontal=x2-x1
vertical=y2-y1
horizontal_squared=horizontal**2
vertical_squared=vertical**2
distance=math.sqrt(horizontal_squared+vertical_squared)
print(distance)
def area(radius):
math.pi*radius**2
def area_circle(xc,yc,xp,yp):
r=distance(xc,yc,xp,yp)
result=area(r)
print (result)
area_circle(1,2,3,6)
Please find time to reply!
I wanted to write code for calculating the area of a circle as present in Allen Downey's book. I first defined a function 'distance' using the distance formula. Then, I defined a function 'area' using radius as an argument. Then I created a third function for calculating the area of the circle calling the previous two functions, distance and area but I think Python is treating my distance function as a Nonetype variable or something.
You need to use
returnso that subsequent functions can make use of the calculations you made indistanceandarea: