Python circle area check using Boolean logic
9. Point-in-Circle Checker
Write a Python program that creates a function that determines if a given point (x, y) is within a specified circle area using boolean conditions.
Sample Solution:
Code:
import math
def check_point_in_circle(x, y, center_x, center_y, radius):
distance = math.sqrt((x - center_x)**2 + (y - center_y)**2)
return distance <= radius
def main():
try:
center_x = float(input("Input x-coordinate of the circle center: "))
center_y = float(input("Input y-coordinate of the circle center: "))
radius = float(input("Input the radius of the circle: "))
point_x = float(input("Input x-coordinate of the point: "))
point_y = float(input("Input y-coordinate of the point: "))
if check_point_in_circle(point_x, point_y, center_x, center_y, radius):
print("The point is within the circle area.")
else:
print("The point is not within the circle area.")
except ValueError:
print("Invalid input. Please Input valid coordinates and radius.")
if __name__ == "__main__":
main()
Output:
Input x-coordinate of the circle center: 10 Input y-coordinate of the circle center: 10 Input the radius of the circle: 50 Input x-coordinate of the point: 2 Input y-coordinate of the point: 3 The point is within the circle area.
Input x-coordinate of the circle center: 5 Input y-coordinate of the circle center: 4 Input the radius of the circle: 4 Input x-coordinate of the point: 8 Input y-coordinate of the point: 9 The point is not within the circle area.
In the exercise above the program prompts the user to input the coordinates of the circle's center, the radius of the circle, and the coordinates of the point. Based on the distance between the point and the circle center, "is_point_in_circle()" determines if the point is within the circle area. It prints the appropriate message based on the results.
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to determine if a point (x, y) lies within a circle with a given center and radius using boolean logic.
- Write a Python function that calculates the Euclidean distance from a point to a circle’s center and uses a boolean check to see if it’s inside the circle.
- Write a Python script to check multiple points against a circle’s boundary and print True for points inside and False for points outside.
- Write a Python program to verify if a point is within a circle by comparing the squared distance with the squared radius, returning a boolean value.
Python Code Editor :
Previous:Python email validation using Boolean logic.
Next: Python user authentication using Boolean logic.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.