Area of circle in python – Python Program for Area of a Circumscribed Circle of a Square

Area of circle in python: In the previous article, we have discussed Python Program to Check if a given Circle lies Completely Inside the Ring formed by Two Concentric Circles
Given the side length of a square, the task is to calculate the area of a circumscribed circle around the given square.

Formula:

(pi * s* s)/2

where pi= 3.14159265

s = side length of square.

Examples:

Example1:

Input:

Given side of square = 5

Output:

The area of an circumscribed circle is for a given square of side { 5 } =  39.27

Example2:

Input:

Given side of square = 8

Output:

The area of an circumscribed circle is for a given square of side { 8 } =  100.53

Program for Area of a Circumscribed Circle of a Square in Python

Below are the ways to calculate the area of a circumscribed circle around the given square in python:

Method #1: Using Mathematical Formula (Static Input)

Approach:

• Give the side of a square as static input and store it in a variable.
• Take a variable and initialize it with the pi value of 3.14159265.
• Create a function to say Find_areacircumscribdcirle() which takes the given side length of the square as an argument, and returns the area of a circumscribed circle around the given square.
• Inside the function, calculate the area of a circumscribed circle around the given square using the above mathematical formula and store it in a variable.
• Return the above result.
• Pass the given side length of the square as an argument to the Find_areacircumscribdcirle() function and store it in another variable.
• Print the above result by rounding off to the 2 places after the decimal point using the round() function.
• The Exit of the Program.

Below is the implementation:

# Create a function to say Find_areacircumscribdcirle() which takes the given side
# length of the square as an argument, and returns the area of a circumscribed
# circle around the given square.

def Find_areacircumscribdcirle(sideof_sqre):
# Inside the function, calculate the area of a circumscribed circle around the given
# square using the above mathematical formula and store it in a variable.
circl_area = (sideof_sqre * sideof_sqre * (pi / 2))
# Return the above result.
return circl_area

# Give the side of a square as static input and store it in a variable.
sideof_sqre = 5
# Take a variable and initialize it with the pi value of 3.14159265.
pi = 3.14159265
# Pass the given side length of the square as an argument to the
# Find_areacircumscribdcirle() function and store it in another variable.
fnl_rsltarea = Find_areacircumscribdcirle(sideof_sqre)
# Print the above result by rounding off to the 2 places after the decimal point using
# the round() function.
print("The area of an circumscribed circle is for a given square of side {", sideof_sqre, "} = ",
round(fnl_rsltarea, 2))


Output:

The area of an circumscribed circle is for a given square of side { 5 } =  39.27

Method #2: Using Mathematical Formula (User Input)

Approach:

• Give the side of a square as user input using the float(input()) function and store it in a variable.
• Take a variable and initialize it with the pi value of 3.14159265.
• Create a function to say Find_areacircumscribdcirle() which takes the given side length of the square as an argument, and returns the area of a circumscribed circle around the given square.
• Inside the function, calculate the area of a circumscribed circle around the given square using the above mathematical formula and store it in a variable.
• Return the above result.
• Pass the given side length of the square as an argument to the Find_areacircumscribdcirle() function and store it in another variable.
• Print the above result by rounding off to the 2 places after the decimal point using the round() function.
• The Exit of the Program.

Below is the implementation:

# Create a function to say Find_areacircumscribdcirle() which takes the given side
# length of the square as an argument, and returns the area of a circumscribed
# circle around the given square.

def Find_areacircumscribdcirle(sideof_sqre):
# Inside the function, calculate the area of a circumscribed circle around the given
# square using the above mathematical formula and store it in a variable.
circl_area = (sideof_sqre * sideof_sqre * (pi / 2))
# Return the above result.
return circl_area

# Give the side of a square as user input using the float(input()) function and
# store it in a variable.
sideof_sqre = float(input("Enter some random number = "))
# Take a variable and initialize it with the pi value of 3.14159265.
pi = 3.14159265
# Pass the given side length of the square as an argument to the
# Find_areacircumscribdcirle() function and store it in another variable.
fnl_rsltarea = Find_areacircumscribdcirle(sideof_sqre)
# Print the above result by rounding off to the 2 places after the decimal point using
# the round() function.
print("The area of an circumscribed circle is for a given square of side {", sideof_sqre, "} = ",
round(fnl_rsltarea, 2))


Output:

Enter some random number = 8
The area of an circumscribed circle is for a given square of side { 8.0 } = 100.53

Access the big list of Python Programming Code Examples with actual logical code asked in Programming and Coding Interviews for Python and stand out from the crowd.