Home > OS >  What to do in order to return True or False instead of the actual distance of the circle?
What to do in order to return True or False instead of the actual distance of the circle?

Time:03-27

The code below is returning the actual distance of the circle. But I want to return True or False. This is supposed to return False as the actual distance is less than the circle's radius. Why is it not returning False? What should I do?

class Point:
 x = 0
 y = 0
class Circle:
 center = Point ()
 radius = 0

def point_in_circle(c, p):
  w = math.sqrt((p.x - c.center.x)**2   (p.y - c.center.y)**2)
  return w
  if w < c.radius:
   return True
  else:
   return False

c = Circle()
c.center.x, c.center.y, c.radius = 0, 0, 1

p = Point()
p.x, p.y = 1, 1

print (point_in_circle(c, p))

CodePudding user response:

you have a return w in point_in_circle() and then a condition by the way you can just return w < c.radius - no need to do the if

  • Related