In the previous article, we have discussed Python Program to Check If a Line Touches or Intersects a Circle

Given two circles of radius r and R, their centers are both at the origin. Given another circle with radius r1 and center at (x1, y1). Check to see if the third circle (circle of radius r1) is entirely contained within the ring formed by two circles of radius r and R

**Examples:**

**Example1:**

**Input:**

Given r = 8 Given R = 4 Given r1 = 2 Given x1 = 6 Given y1 = 0

**Output:**

The given circle lies inside the ring

**Example2:**

**Input:**

Given r = 7 Given R = 10 Given r1 = 5 Given x1 = 2 Given y1 = 6

**Output:**

The given circle does not lies inside the ring

## Program to Check if a given Circle lies Completely Inside the Ring formed by Two Concentric Circles

Below are the ways to check if the given circle is enclosed completely inside the ring formed by the given two circles in Python:

Pythagoras’ Theorem can be used to solve this problem. Using Pythagoras’ theorem, calculate the distance between the center of the circle and the origin, denoted by ‘dis’.

Simply check that the value of** (dis â€“ r1)> = r and (dis + r1)<Â = R** after computing the distance. If both of these conditions are met, the circle is completely enclosed within the ring.

### Method #1: Using Mathematical Approach(Static Input)

**Approach:**

- import the math module using the import keyword
- Give the first circle radius(small circle) r as static input and store it in a variable say rVal.
- Give the second circle radius (Big circle) R as static input and store it in another variable say RVal.
- Give the Third Circle(Which we want to check Condition) radius r1 as static input and store it in another variable say r1Val.
- Give the x coordinates and y coordinates of the third circle and store them in two separate variables.
- Calculate the distance(dis value) using Pythagoras theorem and sqrt() function and store the result in a variable say disVal.
- Check the Condition
**(dis â€“ r1)> = r and (dis + r1)< = RÂ**using the if conditional Statement. - If it is true then Print the given circle inside the ring
- Else print the circle does not lie inside.
- The Exit of the Program.

**Below is the implementation:**

# import the math module using the import keyword import math # Give the first circle radius(small circle) r as static input and # store it in a variable say rVal. rVal = 8 # Give the second circle radius (Big circle) R as static input and # store it in another variable say RVal. RVal = 4 # Give the Third Circle(Which we want to check Condition) radius r1 as # static input and store it in another variable say r1Val r1Val = 2 # Give the x coordinates and y coordinates of the third circle and # store them in two separate variables. xCoordinate = 6 yCoordinate = 0 # Calculate the distance(dis value) using Pythagoras theorem and sqrt() function # and store the result in a variable say disVal. disVal = math.sqrt(xCoordinate * xCoordinate + yCoordinate * yCoordinate) # Check the Condition (dis â€“ r1)> = r and (dis + r1)< = RÂ # using the if conditional Statement. if((disVal-r1Val >= RVal and disVal+r1Val <= rVal)): # If it is true then Print the given circle inside the ringÂ print('The given circle lies inside the ring') else: # Else print the circle does not lie inside. print('The given circle does not lies inside the ring')

**Output:**

The given circle lies inside the ring

### Method #2: Using Mathematical Approach (User Input)

**Approach:**

- import the math module using the import keyword
- Give the first circle radius(small circle) r as user input using the int(input()) function and store it in a variable say rVal.
- Give the second circle radius (Big circle) R as user input using the int(input()) function and store it in another variable say RVal.
- Give the Third Circle(Which we want to check Condition) radius r1 as user input using the int(input()) function and store it in another variable say r1Val.
- Give the x coordinates and y coordinates of the third circle as user input using the map, input(), int(), split() function and store them in two separate variables.
- Calculate the distance(dis value) using Pythagoras theorem and sqrt() function and store the result in a variable say disVal.
- Check the Condition
**(dis â€“ r1)> = r and (dis + r1)< = RÂ**using the if conditional Statement. - If it is true then Print the given circle inside the ring
- Else print the circle does not lie inside.
- The Exit of the Program.

**Below is the implementation:**

# import the math module using the import keyword import math # Give the first circle radius(small circle) r as user input using the int(input()) function and store it in a variable say rVal. rVal = int(input('Enter some random first circle radius = ')) # Give the second circle radius (Big circle) R as user input using the int(input()) function and store it in another variable say RVal. RVal = int(input('Enter some random second circle radius = ')) # Give the Third Circle(Which we want to check Condition) radius r1 as user input using the int(input()) function and store it in another variable say r1Val. r1Val = int(input('Enter some random Third circle radius = ')) # Give the x coordinates and y coordinates of the third circle as user input using the map, input(), int(), split() function # and store them in two separate variables. xCoordinate, yCoordinate = map(int, input( 'Enter some random x and y coordinates separated by spaces = ').split()) # Calculate the distance(dis value) using Pythagoras theorem and sqrt() function # and store the result in a variable say disVal. disVal = math.sqrt(xCoordinate * xCoordinate + yCoordinate * yCoordinate) # Check the Condition (dis â€“ r1)> = r and (dis + r1)< = RÂ # using the if conditional Statement. if((disVal-r1Val >= RVal and disVal+r1Val <= rVal)): # If it is true then Print the given circle inside the ringÂ print('The given circle lies inside the ring') else: # Else print the circle does not lie inside. print('The given circle does not lies inside the ring')

**Output:**

Enter some random first circle radius = 7 Enter some random second circle radius = 10 Enter some random Third circle radius = 5 Enter some random x and y coordinates separated by spaces = 2 6 The given circle does not lies inside the ring

The best way to learn Python for Beginners is to practice as much as they can taking help of the Sample Python Programs For Beginners. Using them you can develop code on your own and master coding skills.