15,907,497 members
See more:
Why am I getting the error message "TypeError: unsupported operand type(s) for ** or pow(): 'NoneType' and 'int'", when I run the following code?

Python
```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_circle(xc,yc,xp,yp):
r=distance(xc,yc,xp,yp)
result=area(r)
print (result)

area_circle(1,2,3,6)```

What I have tried:

I am trying to calculate the area of a circle. I created a function for distance and for area and then I called both of them within another function, area_circle. But, I think there that the distance function has type None. There is something wrong with the r variable which I have assigned to the function distance or there is something wrong with the distance function itself.
Posted
Updated 7-Oct-23 20:55pm
v2

## Solution 1

Neither of your `distance` or `area` functions return a value:, but the code calling the functions expects them to.

See here: Python Function Return Value[^] and try this:
Python
```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)
return(distance)

def area_circle(xc,yc,xp,yp):
r=distance(xc,yc,xp,yp)
result=area(r)
return(result)

print(area_circle(1,2,3,6))```
Be aware though that you will get "odd" results: your area does not have to be square so your circle may be more of an ellipse or will exceed the boundaries of your given area.

Baziga 8-Oct-23 5:38am
Really grateful to you! Thank you so much!
OriginalGriff 8-Oct-23 6:01am
You're welcome!