Python Program for Minimum Height of a Triangle with Given Base and Area

Program for Minimum Height of a Triangle with Given Base and Area

In the previous article, we have discussed Python Program to Calculate Volume and Surface Area of Hemisphere
Given the area(a) and the base(b) of the triangle, the task is to find the minimum height so that a triangle of least area a and base b can be formed.

Knowing the relationship between the three allows you to calculate the minimum height of a triangle with base “b” and area “a.”

The relationship between area, base, and height:

area = (1/2) * base * height

As a result, height can be calculated as follows:

height = (2 * area)/ base

Examples:

Example1:

Input:

Given area = 6
Given base = 3

Output:

The minimum height so that a triangle of the least area and base can be formed =  4

Example2:

Input:

Given area = 7
Given base = 5

Output:

The minimum height so that a triangle of the least area and base can be formed = 3

Program for Minimum Height of a Triangle with Given Base and Area in Python

Below are the ways to find the minimum height so that a triangle of least area a and base b can be formed:

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Import math module using the import keyword.
  • Give the area as static input and store it in a variable.
  • Give the base as static input and store it in another variable.
  • Create a function to say Smallest_height() which takes the given area and base of the triangle as the arguments and returns the minimum height so that a triangle of least area and base can be formed.
  • Inside the function, calculate the value of (2*gvn_areaoftri)/gvn_baseoftri using the above mathematical formula and store it in another variable.
  • Apply math.ceil() function to the above result and return the minimum height.
  • Pass the given area and base of the triangle as the arguments to the Smallest_height() function and store it in a variable.
  • Print the above result i.e, minimum height so that a triangle of the least area and base can be formed.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math

# Create a function to say Smallest_height() which takes the given area and base
# of the triangle as the arguments and returns the minimum height so that a
# triangle of least area and base can be formed.


def Smallest_height(gvn_areaoftri, gvn_baseoftri):
    # Inside the function, calculate the value of (2*gvn_areaoftri)/gvn_baseoftri using
    # the above mathematical formula and store it in another variable.
    rslt = (2*gvn_areaoftri)/gvn_baseoftri
    # Apply math.ceil() function to the above result and return the minimum height.
    return math.ceil(rslt)


# Give the area as static input and store it in a variable.
gvn_areaoftri = 6
# Give the base as static input and store it in another variable.
gvn_baseoftri = 3
# Pass the given area and base of the triangle as the arguments to the Smallest_height()
# function and store it in a variable.
min_heigt = Smallest_height(gvn_areaoftri, gvn_baseoftri)
# Print the above result i.e, minimum height so that a triangle of the least area
# and base can be formed.
print("The minimum height so that a triangle of the least area and base can be formed = ", min_heigt)

Output:

The minimum height so that a triangle of the least area and base can be formed =  4

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Import math module using the import keyword.
  • Give the area as user input using the int(input()) function and store it in a variable.
  • Give the base as user input using the int(input()) function and store it in another variable.
  • Create a function to say Smallest_height() which takes the given area and base of the triangle as the arguments and returns the minimum height so that a triangle of least area and base can be formed.
  • Inside the function, calculate the value of (2*gvn_areaoftri)/gvn_baseoftri using the above mathematical formula and store it in another variable.
  • Apply math.ceil() function to the above result and return the minimum height.
  • Pass the given area and base of the triangle as the arguments to the Smallest_height() function and store it in a variable.
  • Print the above result i.e, minimum height so that a triangle of the least area and base can be formed.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math

# Create a function to say Smallest_height() which takes the given area and base
# of the triangle as the arguments and returns the minimum height so that a
# triangle of least area and base can be formed.


def Smallest_height(gvn_areaoftri, gvn_baseoftri):
    # Inside the function, calculate the value of (2*gvn_areaoftri)/gvn_baseoftri using
    # the above mathematical formula and store it in another variable.
    rslt = (2*gvn_areaoftri)/gvn_baseoftri
    # Apply math.ceil() function to the above result and return the minimum height.
    return math.ceil(rslt)


# Give the area as user input using the int(input()) function and store it in a variable.
gvn_areaoftri = int(input("Enter some random number = "))
# Give the base as user input using the int(input()) function and 
# store it in another variable.
gvn_baseoftri = int(input("Enter some random number = "))
# Pass the given area and base of the triangle as the arguments to the Smallest_height()
# function and store it in a variable.
min_heigt = Smallest_height(gvn_areaoftri, gvn_baseoftri)
# Print the above result i.e, minimum height so that a triangle of the least area
# and base can be formed.
print("The minimum height so that a triangle of the least area and base can be formed = ", min_heigt)

Output:

Enter some random number = 7
Enter some random number = 5
The minimum height so that a triangle of the least area and base can be formed = 3

If you are learning Python then the Python Programming Example is for you and gives you a thorough description of concepts for beginners, experienced programmers.

Python Program for Maximum Area of Quadrilateral

Program for Maximum Area of Quadrilateral

In the previous article, we have discussed Python Program for Circumference of a Parallelogram
Given four sides of a quadrilateral, the task is to get the maximum area of the given quadrilateral for the given four sides in python.

Quadrilateral:

In geometry, a quadrilateral is a closed shape formed by joining four points, any three of which are non-collinear. A quadrilateral is made up of four sides, four angles, and four vertices. The term ‘quadrilateral’ is derived from the Latin words ‘quadra’ (four) and ‘Latus’ (sides). A quadrilateral’s four sides may or may not be equal.

Formula:

The formula to calculate the maximum area of the given quadrilateral is :

K={sqrt {(s-a)(s-b)(s-c)(s-d)}}

This is known as  Brahmagupta’s Formula.

s=(a+b+c+d)/2

where a, b, c, d are the four sides of a quadrilateral.

Examples:

Example1:

Input:

Given first side = 2
Given second side = 1
Given third side =  3
Given fourth side =  4

Output:

The maximimum area of quadrilateral for the given four sides { 2 , 1 , 3 , 4 } =  4.898979485566356

Example2:

Input:

Given first side = 5
Given second side = 3
Given third side = 5
Given fourth side = 2

Output:

The maximimum area of quadrilateral for the given four sides { 5 , 3 , 5 , 2 } =  12.43734296383275

Program for Maximum Area of Quadrilateral in Python

Below are the ways to get the maximum area of the given quadrilateral for the given four sides in python:

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Import math module using the import keyword.
  • Give the first side as static input and store it in a variable.
  • Give the second side as static input and store it in another variable.
  • Give the third side as static input and store it in another variable.
  • Give the fourth side as static input and store it in another variable.
  • Calculate the s value using the above given mathematical formula and store it in another variable.
  • Calculate the maximum area of the given quadrilateral using the above given mathematical formula, math.sqrt() function and store it in another variable.
  • Print the maximum area of the given quadrilateral.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the first side as static input and store it in a variable.
p = 2
# Give the second side as static input and store it in another variable.
q = 1
# Give the third side as static input and store it in another variable.
r = 3
# Give the fourth side as static input and store it in another variable.
s = 4
# Calculate the s value using the above given mathematical formula and 
# store it in another variable.
s_valu = (p + q + r + s) / 2
# Calculate the maximum area of the given quadrilateral using the above
# given mathematical formula, math.sqrt() function and store it in another variable.
quadriltrlmax_area = math.sqrt(
    (s_valu - p) * (s_valu - q) * (s_valu - r) * (s_valu - s))
# Print the maximum area of the given quadrilateral.
print(
    "The maximimum area of quadrilateral for the given four sides {", p, ",", q, ",", r, ",", s, "} = ", quadriltrlmax_area)
# include <iostream>
# include<cmath>
using namespace std

int main() {
    int p = 2
    int q = 1
    int r = 3
    int s = 4
    int s_valu = (p + q + r + s) / 2
    double quadriltrlMaxArea = sqrt((s_valu - p) * (s_valu - q) * (s_valu - r) * (s_valu - s))
    cout << "The maximimum area of quadrilateral for the given four sides {" << p << "," << q << "," << r << "," << s << "} = " << quadriltrlMaxArea << endl
    return 0
}

Output:

The maximimum area of quadrilateral for the given four sides { 2 , 1 , 3 , 4 } =  4.898979485566356

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Import math module using the import keyword.
  • Give the first side as user input using the int(input()) function and store it in a variable.
  • Give the second side as user input using the int(input()) function and store it in another variable.
  • Give the third side as user input using the int(input()) function and store it in another variable.
  • Give the fourth side as user input using the int(input()) function and store it in another variable.
  • Calculate the s value using the above given mathematical formula and store it in another variable.
  • Calculate the maximum area of the given quadrilateral using the above given mathematical formula, math.sqrt() function and store it in another variable.
  • Print the maximum area of the given quadrilateral.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the first side as user input using the int(input()) function and store it in a variable.
p = int(input("Enter some random number = "))
# Give the second side as user input using the int(input()) function and store it in another variable.
q = int(input("Enter some random number = "))
# Give the third side as user input using the int(input()) function and store it in another variable.
r = int(input("Enter some random number = "))
# Give the fourth side as user input using the int(input()) function and store it in another variable.
s = int(input("Enter some random number = "))
# Calculate the s value using the above given mathematical formula and 
# store it in another variable.
s_valu = (p + q + r + s) / 2
# Calculate the maximum area of the given quadrilateral using the above
# given mathematical formula, math.sqrt() function and store it in another variable.
quadriltrlmax_area = math.sqrt(
    (s_valu - p) * (s_valu - q) * (s_valu - r) * (s_valu - s))
# Print the maximum area of the given quadrilateral.
print(
    "The maximimum area of quadrilateral for the given four sides {", p, ",", q, ",", r, ",", s, "} = ", quadriltrlmax_area)

Output:

Enter some random number = 5
Enter some random number = 3
Enter some random number = 5
Enter some random number = 2
The maximimum area of quadrilateral for the given four sides { 5 , 3 , 5 , 2 } = 12.43734296383275

Output:

Python Program for Pythagorean Quadruple

Program for Pythagorean Quadruple

In the previous article, we have discussed Python Program to Calculate Area and Volume of a Tetrahedron
Given four points, the task is to check if the given four points form quadruple in python.

Quadruple:

It is defined as a tuple of integers a, b, c, and d such that a2 + b2  + c2 = d2. They are, in fact, Diophantine Equations solutions. It represents a cuboid with integer side lengths |a|, |b|, and |c| and a space diagonal of |d| in the geometric interpretation.

Condition to check Quadruple = a2 + b2  + c2 = d2

where a, b, c, d are the given four points.

Examples:

Example1:

Input:

Given first point = 6
Given second point = 2
Given third point = 3
Given fourth point = 7

Output:

The given four points { 6 , 2 , 3 , 7 } forms a quadruple

Example2:

Input:

Given first point = 9
Given second point = 2
Given third point = 6 
Given fourth point = 11

Output:

The given four points { 9 , 2 , 6 , 11 } forms a quadruple

Program for Pythagorean Quadruple in Python

Below are the ways to check if the given four points form quadruple in python:

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Give the first number as static input and store it in a variable.
  • Give the second number as static input and store it in another variable.
  • Give the third number as static input and store it in another variable.
  • Give the fourth number as static input and store it in another variable.
  • Calculate the sum of squares of the given three numbers using the above given mathematical formula and store it in another variable.
  • Check if the above result sum is equal to the square of the fourth number using the if conditional statement.
  • If it is true, then print “The given four points forms a quadruple”.
  • Else print “The given four points do not form a quadruple”.
  • The Exit of the Program.

Below is the implementation:

# Give the first number as static input and store it in a variable.
p = 6
# Give the second number as static input and store it in another variable.
q = 2
# Give the third number as static input and store it in another variable.
r = 3
# Give the fourth number as static input and store it in another variable.
s = 7
# Calculate the sum of squares of the given three numbers using the above given
# mathematical formula and store it in another variable.
rslt_sum = p * p + q * q + r * r
# Check if the above result sum is equal to the square of the fourth number 
# using the if conditional statement.
if (s * s == rslt_sum):
    # If it is true, then print "The given four points forms a quadruple".
    print("The given four points {", p, ",", q,
          ",", r, ",", s, "} forms a quadruple")
# Else print "The given four points do not form a quadruple".
else:
    print("The given four points {", p, ",", q,
          ",", r, ",", s, "} do not form a quadruple")
# include <iostream>

using namespace std

int main() {
    double p = 6
    double q = 12
    double r = 3
    double s = 7
    double rslt_sum = p * p + q * q + r * r
    if ((s * s == rslt_sum)) {
        cout << "The given four points {" << p << "," << q << "," << r << "," << s << "} forms a quadruple" << endl
    }
    else {
        cout << "The given four points {" << p << "," << q << "," << r << "," << s << "} do not form a quadruple" << endl
    }

}

Output:

The given four points { 6 , 2 , 3 , 7 } forms a quadruple

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Give the first number as user input using the int(input()) function and store it in a variable.
  • Give the second number as user input using the int(input()) function and store it in another variable.
  • Give the third number as user input using the int(input()) function and store it in another variable.
  • Give the fourth number as user input using the int(input()) function and store it in another variable.
  • Calculate the sum of squares of the given three numbers using the above given mathematical formula and store it in another variable.
  • Check if the above result sum is equal to the square of the fourth number using the if conditional statement.
  • If it is true, then print “The given four points forms a quadruple”.
  • Else print “The given four points do not form a quadruple”.
  • The Exit of the Program.

Below is the implementation:

# Give the first number as user input using the int(input()) function and store it in a variable.
p = int(input("Enter some random number = "))
# Give the second number as user input using the int(input()) function and store it in another variable.
q = int(input("Enter some random number = "))
# Give the third number as user input using the int(input()) function and store it in another variable.
r = int(input("Enter some random number = "))
# Give the fourth number as user input using the int(input()) function and store it in another variable.
s = int(input("Enter some random number = "))
# Calculate the sum of squares of the given first three numbers using the above given
# mathematical formula and store it in another variable.
rslt_sum = p * p + q * q + r * r
# Check if the above result sum is equal to the square of the fourth number
# using the if conditional statement.
if (s * s == rslt_sum):
    # If it is true, then print "The given four points forms a quadruple".
    print("The given four points {", p, ",", q,
          ",", r, ",", s, "} forms a quadruple")
# Else print "The given four points do not form a quadruple".
else:
    print("The given four points {", p, ",", q,
          ",", r, ",", s, "} do not form a quadruple")

Output:

Enter some random number = 9
Enter some random number = 2
Enter some random number = 6
Enter some random number = 11
The given four points { 9 , 2 , 6 , 11 } forms a quadruple

Python Program for Set copy() Method

Program for Set copy() Method

In the previous article, we have discussed Python Program for Set clear() Method
Python set:

Python set is a list of items that are not ordered. – Each element in the set must be unique and immutable, and duplicate elements are removed from the sets. Sets are mutable, which means they can be changed after they have been created.

The elements of the set, unlike other Python sets, do not have an index, which means we cannot access any element of the set directly using the index. To get the list of elements, we can either print them all at once or loop them through the collection.

Examples:

Example1:

Input:

Given set = {'hello', 'this', 'is', 'btechgeeks'}

Output:

The given set is :
{'this', 'hello', 'btechgeeks', 'is'}
The New set after copying all the values from the given set is:
{'this', 'hello', 'btechgeeks', 'is'}

Explanation:

Here all the values of the given set are copied into the new set using the copy() function.

Example2:

Input:

Given set = {'good', 'morning', 'btechgeeks'}

Output:

The given set is :
{'btechgeeks', 'morning', 'good'}
The New set after copying all the values from the given set is:
{'btechgeeks', 'morning', 'good'}

Explanation:

Here all the values of the given set are copied into the new set using the copy() function.

Program for Set copy() Method in Python

set copy() Method:

The Python set copy method is used to copy the entire set into a new set.

Syntax:

set.copy()

Parameters: The copy() method for sets does not accept any parameters.

Return value: The function returns a shallow copy of the original set as its return value.

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the set as static input and initialize it with some random values.
  • Store it in a variable.
  • Print the above-given set.
  • Apply copy() function to the given set to copy all its elements into the new set.
  • Store it in another variable.
  • Print the above new set after copying all the values from the given set.
  • The Exit of Program.

Below is the implementation:

# Give the set as static input and initialize it with some random values.
# Store it in a variable.
gven_set = {'hello', 'this', 'is', 'btechgeeks'}
# Print the above-given set.
print("The given set is :")
print(gven_set)
# Apply copy() function to the given set to copy all its elements into the new set.
# Store it in another variable.
gvnset_copy = gven_set.copy()
# Print the above new set after copying all the values from the given set
print("The New set after copying all the values from the given set is:")
print(gvnset_copy)

Output:

The given set is :
{'this', 'hello', 'btechgeeks', 'is'}
The New set after copying all the values from the given set is:
{'this', 'hello', 'btechgeeks', 'is'}

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the set as user input using the set(), input(), and split() functions.
  • Store it in a variable.
  • Print the above-given set.
  • Apply copy() function to the given set to copy all its elements into the new set.
  • Store it in another variable.
  • Print the above new set after copying all the values from the given set.
  • The Exit of Program.

Below is the implementation:

# Give the set as user input using the set(), input(), and split() functions.
# Store it in a variable.
gven_set = set(input("Enter some random values separated by spaces = ").split())
# Print the above-given set.
print("The given set is :")
print(gven_set)
# Apply copy() function to the given set to copy all its elements into the new set.
# Store it in another variable.
gvnset_copy = gven_set.copy()
# Print the above new set after copying all the values from the given set
print("The New set after copying all the values from the given set is:")
print(gvnset_copy)

Output:

Enter some random values separated by spaces = good morning btechgeeks
The given set is :
{'morning', 'btechgeeks', 'good'}
The New set after copying all the values from the given set is:
{'morning', 'btechgeeks', 'good'}

Python Program for set add() Method

Program for set add() Method

In the previous article, we have discussed Python Program for Dictionary items() Function
Python set:

Python set is a list of items that are not ordered. – Each element in the set must be unique and immutable, and duplicate elements are removed from the sets. Sets are mutable, which means they can be changed after they have been created.

The elements of the set, unlike other Python sets, do not have an index, which means we cannot access any element of the set directly using the index. To get the list of elements, we can either print them all at once or loop them through the collection.

Examples:

Example1:

Input:

Given set =  {'hello', 'this', 'is'}
Value to be added = 'btechgeeks'

Output:

The given set is :
{'this', 'is', 'hello'}
The set is after a given element to the above given set :
{'this', 'is', 'hello', 'btechgeeks'}

Example2:

Input:

Given set = {'good', 'morning', 'this', 'is', 'btechgeeks'}
Value to be added = 'hello'

Output:

The given set is :
{'this', 'btechgeeks', 'good', 'is', 'morning'}
The set is after a given element to the above given set :
{'this', 'hello', 'btechgeeks', 'good', 'is', 'morning'}

Program for Set add() Method in Python

add() Function in set:

The set add() function in Python is used to add a new item to an existing set.

The syntax is as follows:

set_Name.add(element)

The python set add() function only accepts one parameter. You can, however, use a tuple as an argument. Remember that you cannot use this add() method to add an existing (duplicate value) to a set.

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the set as static input and initialize it with some random values.
  • Store it in a variable.
  • Print the above-given set.
  • Add a new value to the given set by using the add() function.
  • Print the above-given set after adding a given new value.
  • The Exit of Program.

Below is the implementation:

# Give the set as static input and initialize it with some random values.
# Store it in a variable.
gven_set = {'hello', 'this', 'is'}
# Print the above-given set.
print("The given set is :")
print(gven_set)
# Add a new value to the given set by using the add() function.
gven_set.add('btechgeeks')
# Print the above-given set after adding a given new value.
print("The set is after a given element to the above given set :")
print(gven_set)

Output:

The given set is :
{'this', 'is', 'hello'}
The set is after a given element to the above given set :
{'this', 'is', 'hello', 'btechgeeks'}

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the set as user input using the set(), input(), and split() functions.
  • Store it in a variable.
  • Print the above-given set.
  • Give the value to be added as user input using the input() function and store it in another variable.
  • Add the above value to the given set by using the add() function.
  • Print the above-given set after adding a given new value.
  • The Exit of Program.

Below is the implementation:

# Give the set as user input using the set(), input(), and split() functions.
# Store it in a variable.
gven_set = set(input("Enter some random values separated by spaces = ").split())
# Print the above-given set.
print("The given set is :")
print(gven_set)
# Give the value to be added as user input using the input() function and 
# store it in another variable.
k=input("Enter some random value = ")
# Add the above value to the given set by using the add() function.
gven_set.add(k)
# Print the above-given set after adding a given new value.
print("The set is after a given element to the above given set :")
print(gven_set)

Output:

Enter some random values separated by spaces = good morning this is btechgeeks
The given set is :
{'this', 'btechgeeks', 'good', 'is', 'morning'}
Enter some random value = hello
The set is after a given element to the above given set :
{'this', 'hello', 'btechgeeks', 'good', 'is', 'morning'}

II) add Tuple to set :

Method #3: Using Built-in Functions (Static Input)

Approach:

  • Give the set as static input and initialize it with some random values.
  • Store it in a variable.
  • Print the above-given set.
  • Give the tuple as static input and initialize it with some random values.
  • Add the above-given tuple to the given set by using the add() function.
  • Print the above-given set after adding a given tuple.
  • The Exit of Program.

Below is the implementation:

# Give the set as static input and initialize it with some random values.
# Store it in a variable.
gven_set = {11, 12, 13, 14, 15}
# Print the above-given set.
print("The given set is :")
print(gven_set)
# Give the tuple as static input and initialize it with some random values.
gvn_tupl = (16, 17, 18, 19)
# Add the above given tuple to the given set by using the add() function.
gven_set.add(gvn_tupl)
print("The given set after after adding a given tuple:")
# Print the above-given set after adding a given tuple.
print(gven_set)

Output:

The given set is :
{11, 12, 13, 14, 15}
The given set after after adding a given tuple:
{11, 12, 13, 14, 15, (16, 17, 18, 19)}

Python Program to Find Coordinates of Rectangle with Given Points Lie Inside

Program to Find Coordinates of Rectangle with Given Points Lie Inside

In the previous article, we have discussed Python Program to Find Number of Rectangles in N*M Grid
Given Two lists X and Y where X[i] and Y[i] represent the coordinate system’s points.

The task is to Find the smallest rectangle in which all of the points from the given input are enclosed, and the sides of the rectangle must be parallel to the Coordinate axis. Print the obtained rectangle’s four coordinates.

Examples:

Example1:

Input:

Given X Coordinates List = [4, 3, 6, 1, -1, 12 Given Y Coordinates List = [4, 1, 10, 3, 7, -1] 

Output:

The first point of Rectangle is [ -1 , -1 ]
The second point of Rectangle is [ -1 , 10 ]
The third point of Rectangle is [ 12 , 10 ]
The fourth point of Rectangle is [ 12 , -1 ]

Example2:

Input:

Given X Coordinates List =  4 8 7 1 6 4 2
Given Y Coordinates List =  5 7 9 8 3 4 2

Output:

The first point of Rectangle is [ 1 , 2 ]
The second point of Rectangle is [ 1 , 9 ]
The third point of Rectangle is [ 8 , 9 ]
The fourth point of Rectangle is [ 8 , 2 ]

Program to Find Coordinates of Rectangle with Given Points Lie Inside in Python

Below are the ways to Find the smallest rectangle in which all of the points from the given input are enclosed in Python:

The logic behind this is very simple and efficient: find the smallest and largest x and y coordinates among all given points, and then all possible four combinations of these values result in the four points of the required rectangle as [Xmin, Ymin], [Xmin, Ymax], [Xmax, Ymax],[ Xmax, Ymin].

Method #1: Using Mathematical Approach(Static Input)

Approach:

  • Give the X coordinates of all the points as a list as static input and store it in a variable.
  • Give the Y coordinates of all the points as another list as static input and store it in another variable.
  • Calculate the minimum value of all the x Coordinates using the min() function and store it in a variable xMinimum.
  • Calculate the maximum value of all the x Coordinates using the max() function and store it in a variable xMaximum.
  • Calculate the minimum value of all the y Coordinates using the min() function and store it in a variable yMinimum.
  • Calculate the maximum value of all the y Coordinates using the max() function and store it in a variable yMaximum.
  • Print the Four Coordinates of the Rectangle using the above 4 calculated values.
  • Print the first point of the rectangle by printing values xMinimum, yMinimum.
  • Print the second point of the rectangle by printing values xMinimum, yMaximum.
  • Print the third point of the rectangle by printing values xMaximum, yMaximum.
  • Print the fourth point of the rectangle by printing values xMaximum, yMinimum.
  • The Exit of the Program.

Below is the implementation:

#Give the X coordinates of all the points as a list as static input 
#and store it in a variable.
XCordinates=[4, 3, 6, 1, -1, 12] 
#Give the Y coordinates of all the points as another list as static input 
#and store it in another variable.
YCordinates =  [4, 1, 10, 3, 7, -1] 

#Calculate the minimum value of all the x Coordinates using the min() function
#and store it in a variable xMinimum.
xMinimum=min(XCordinates)
#Calculate the maximum value of all the x Coordinates using the max() function 
#and store it in a variable xMaximum.
xMaximum=max(XCordinates)
#Calculate the minimum value of all the y Coordinates using the min() function
#and store it in a variable yMinimum.
yMinimum=min(YCordinates)
#Calculate the maximum value of all the y Coordinates using the max() function
#and store it in a variable yMaximum.
yMaximum=max(YCordinates)
#Print the Four Coordinates of the Rectangle using the above 4 calculated values.
#Print the first point of the rectangle by printing values xMinimum, yMinimum.
print('The first point of Rectangle is [',xMinimum,',',yMinimum,']')
#Print the second point of the rectangle by printing values xMinimum, yMaximum.
print('The second point of Rectangle is [',xMinimum,',',yMaximum,']')
#Print the third point of the rectangle by printing values xMaximum, yMaximum.
print('The third point of Rectangle is [',xMaximum,',',yMaximum,']')
#Print the fourth point of the rectangle by printing values xMaximum, yMinimum.
print('The fourth point of Rectangle is [',xMaximum,',',yMinimum,']')

Output:

The first point of Rectangle is [ -1 , -1 ]
The second point of Rectangle is [ -1 , 10 ]
The third point of Rectangle is [ 12 , 10 ]
The fourth point of Rectangle is [ 12 , -1 ]

Method #2: Using Mathematical Approach (User Input)

Approach:

  • Give the X coordinates of all the points as a list as user input using list(),int(),split(),map() functions and store it in a variable.
  • Give the Y coordinates of all the points as another list as user input using list(),int(),split(),map() functions and store it in another variable.
  • Calculate the minimum value of all the x Coordinates using the min() function and store it in a variable xMinimum.
  • Calculate the maximum value of all the x Coordinates using the max() function and store it in a variable xMaximum.
  • Calculate the minimum value of all the y Coordinates using the min() function and store it in a variable yMinimum.
  • Calculate the maximum value of all the y Coordinates using the max() function and store it in a variable yMaximum.
  • Print the Four Coordinates of the Rectangle using the above 4 calculated values.
  • Print the first point of the rectangle by printing values xMinimum, yMinimum.
  • Print the second point of the rectangle by printing values xMinimum, yMaximum.
  • Print the third point of the rectangle by printing values xMaximum, yMaximum.
  • Print the fourth point of the rectangle by printing values xMaximum, yMinimum.
  • The Exit of the Program.

Below is the implementation:

# Give the X coordinates of all the points as a list as user input using list(),int(),split(),map() functions
# and store it in a variable.
XCordinates = list(map(int, input('Enter some random X Coordinates = ').split()))
# Give the Y coordinates of all the points as another list as user input using list(),int(),split(),map() functions
# and store it in another variable.
YCordinates = list(map(int, input('Enter some random Y Coordinates = ').split()))

# Calculate the minimum value of all the x Coordinates using the min() function
# and store it in a variable xMinimum.
xMinimum = min(XCordinates)
# Calculate the maximum value of all the x Coordinates using the max() function
# and store it in a variable xMaximum.
xMaximum = max(XCordinates)
# Calculate the minimum value of all the y Coordinates using the min() function
# and store it in a variable yMinimum.
yMinimum = min(YCordinates)
# Calculate the maximum value of all the y Coordinates using the max() function
# and store it in a variable yMaximum.
yMaximum = max(YCordinates)
# Print the Four Coordinates of the Rectangle using the above 4 calculated values.
# Print the first point of the rectangle by printing values xMinimum, yMinimum.
print('The first point of Rectangle is [', xMinimum, ',', yMinimum, ']')
# Print the second point of the rectangle by printing values xMinimum, yMaximum.
print('The second point of Rectangle is [', xMinimum, ',', yMaximum, ']')
# Print the third point of the rectangle by printing values xMaximum, yMaximum.
print('The third point of Rectangle is [', xMaximum, ',', yMaximum, ']')
# Print the fourth point of the rectangle by printing values xMaximum, yMinimum.
print('The fourth point of Rectangle is [', xMaximum, ',', yMinimum, ']')

Output:

Enter some random X Coordinates = 4 8 7 1 6 4 2
Enter some random Y Coordinates = 5 7 9 8 3 4 2
The first point of Rectangle is [ 1 , 2 ]
The second point of Rectangle is [ 1 , 9 ]
The third point of Rectangle is [ 8 , 9 ]
The fourth point of Rectangle is [ 8 , 2 ]

Remediate your knowledge gap by attempting the Python Code Examples regularly and understand the areas of need and work on them.

Python Program for Minimum Perimeter of n Blocks

Program for Minimum Perimeter of n Blocks

In the previous article, we have discussed Python Program To Find Area of a Circular Sector
Given n blocks of size 1*1, the task is to find the minimum perimeter of the grid made by these given n blocks in python.

Examples:

Example1:

Input:

Given n value = 6

Output:

The minimum perimeter of the grid made by the given n blocks{ 6 } =  11

Example2:

Input:

Given n value = 9

Output:

The minimum perimeter of the grid made by the given n blocks{ 9 } =  12

Program for Minimum Perimeter of n Blocks in Python

Below are the ways to find the minimum perimeter of the grid made by these given n blocks in python:

Method #1: Using Mathematical Approach (Static Input)

Approach:

  • Import math module using the import keyword.
  • Give the n value as static input and store it in a variable.
  • Create a function to say Minimum_perimtr() which takes the given n value as an argument and returns the minimum perimeter of the grid made by these given n blocks.
  • Calculate the square root of the given n value using the math.sqrt() function and store it in a variable say sqrt_val.
  • Multiply the above result with itself and store it in another variable.
  • Check if the given n value is a perfect square by using the if conditional statement.
  • If it is true, then return the value of above sqrt_val multiplied by 4.
  • Else calculate the number of rows by dividing the given n value by sqrt_val.
  • Add the above sqrt_val with the number of rows obtained and multiply the result by 2 to get the perimeter of the rectangular grid.
  • Store it in another variable.
  • Check whether there are any blocks left using the if conditional statement.
  • If it is true, then add 2 to the above-obtained perimeter of the rectangular grid and store it in the same variable.
  • Return the minimum perimeter of the grid made by the given n blocks.
  • Pass the given n value as an argument to the Minimum_perimtr() function, convert it into an integer using the int() function and store it in another variable.
  • Print the above result which is the minimum perimeter of the grid made by the given n blocks.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math

# Create a function to say Minimum_perimtr() which takes the given n value as an
# argument and returns the minimum perimeter of the grid made by these given n blocks.


def Minimum_perimtr(gvn_n_val):
    # Calculate the square root of the given n value using the math.sqrt() function
    # and store it in a variable say sqrt_val.
    sqrt_val = math.sqrt(gvn_n_val)
    # Multiply the above result with itself and store it in another variable.
    sqre_rslt = sqrt_val * sqrt_val

    # Check if the given n value is a perfect square by using the if
    # conditional statement.
    if (sqre_rslt == gvn_n_val):
        # If it is true, then return the value of above sqrt_val multiplied by 4.
        return sqrt_val * 4
    else:
        # Else calculate the number of rows by dividing the given n value by sqrt_val.
        no_of_rows = gvn_n_val / sqrt_val

        # Add the above sqrt_val with the number of rows obtained and multiply the result
        # by 2 to get the perimeter of the rectangular grid.
        # Store it in another variable.
        rslt_perimetr = 2 * (sqrt_val + no_of_rows)

        # Check whether there are any blocks left using the if conditional statement.
        if (gvn_n_val % sqrt_val != 0):
            # If it is true, then add 2 to the above-obtained perimeter of the rectangular
                    # grid and store it in the same variable.
            rslt_perimetr += 2
        # Return the minimum perimeter of the grid made by the given n blocks.
        return rslt_perimetr


# Give the n value as static input and store it in a variable.
gvn_n_val = 6
# Pass the given n value as an argument to the Minimum_perimtr() function, convert
# it into an integer using the int() function and store it in another variable.
fnl_rslt = int(Minimum_perimtr(gvn_n_val))
# Print the above result which is the minimum perimeter of the grid made by the
# given n blocks.
print(
    "The minimum perimeter of the grid made by the given n blocks{", gvn_n_val, "} = ", fnl_rslt)
#include <iostream>
#include<math.h>
using namespace std;
int Minimum_perimtr ( int gvn_n_val ) {
  int sqrt_val = sqrt ( gvn_n_val );
  int sqre_rslt = sqrt_val * sqrt_val;
  if (  sqre_rslt == gvn_n_val  ) {
    return sqrt_val * 4;
  }
  else {
    int no_of_rows = gvn_n_val / sqrt_val;
    int rslt_perimetr = 2 * ( sqrt_val + no_of_rows );
    if ( ( gvn_n_val % sqrt_val != 0 )  ) {
      rslt_perimetr += 2;
    }
    return rslt_perimetr;
  }
}
int main() {
   int gvn_n_val = 6;
 int fnl_rslt = ( int ) Minimum_perimtr ( gvn_n_val );
  cout << "The minimum perimeter of the grid made by the given n blocks{" << gvn_n_val << "} = " << fnl_rslt << endl;
  return 0;
}



Output:

The minimum perimeter of the grid made by the given n blocks{ 6 } =  11

Method #2: Using Mathematical Approach (User Input)

Approach:

  • Import math module using the import keyword.
  • Give the n value as user input using the int(input()) function input and store it in a variable.
  • Create a function to say Minimum_perimtr() which takes the given n value as an argument and returns the minimum perimeter of the grid made by these given n blocks.
  • Calculate the square root of the given n value using the math.sqrt() function and store it in a variable say sqrt_val.
  • Multiply the above result with itself and store it in another variable.
  • Check if the given n value is a perfect square by using the if conditional statement.
  • If it is true, then return the value of above sqrt_val multiplied by 4.
  • Else calculate the number of rows by dividing the given n value by sqrt_val.
  • Add the above sqrt_val with the number of rows obtained and multiply the result by 2 to get the perimeter of the rectangular grid.
  • Store it in another variable.
  • Check whether there are any blocks left using the if conditional statement.
  • If it is true, then add 2 to the above-obtained perimeter of the rectangular grid and store it in the same variable.
  • Return the minimum perimeter of the grid made by the given n blocks.
  • Pass the given n value as an argument to the Minimum_perimtr() function, convert it into an integer using the int() function and store it in another variable.
  • Print the above result which is the minimum perimeter of the grid made by the given n blocks.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math

# Create a function to say Minimum_perimtr() which takes the given n value as an
# argument and returns the minimum perimeter of the grid made by these given n blocks.


def Minimum_perimtr(gvn_n_val):
    # Calculate the square root of the given n value using the math.sqrt() function
    # and store it in a variable say sqrt_val.
    sqrt_val = math.sqrt(gvn_n_val)
    # Multiply the above result with itself and store it in another variable.
    sqre_rslt = sqrt_val * sqrt_val

    # Check if the given n value is a perfect square by using the if
    # conditional statement.
    if (sqre_rslt == gvn_n_val):
        # If it is true, then return the value of above sqrt_val multiplied by 4.
        return sqrt_val * 4
    else:
        # Else calculate the number of rows by dividing the given n value by sqrt_val.
        no_of_rows = gvn_n_val / sqrt_val

        # Add the above sqrt_val with the number of rows obtained and multiply the result
        # by 2 to get the perimeter of the rectangular grid.
        # Store it in another variable.
        rslt_perimetr = 2 * (sqrt_val + no_of_rows)

        # Check whether there are any blocks left using the if conditional statement.
        if (gvn_n_val % sqrt_val != 0):
            # If it is true, then add 2 to the above-obtained perimeter of the rectangular
                    # grid and store it in the same variable.
            rslt_perimetr += 2
        # Return the minimum perimeter of the grid made by the given n blocks.
        return rslt_perimetr


# Give the n value as user input using the int(input()) function input and
# store it in a variable.
gvn_n_val = int(input("Enter some random number = "))
# Pass the given n value as an argument to the Minimum_perimtr() function, convert
# it into an integer using the int() function and store it in another variable.
fnl_rslt = int(Minimum_perimtr(gvn_n_val))
# Print the above result which is the minimum perimeter of the grid made by the
# given n blocks.
print(
    "The minimum perimeter of the grid made by the given n blocks{", gvn_n_val, "} = ", fnl_rslt)

Output:

Enter some random number = 9
The minimum perimeter of the grid made by the given n blocks{ 9 } = 12

If you are learning Python then the Python Programming Example is for you and gives you a thorough description of concepts for beginners, experienced programmers.

Python Program for Arc Length from Given Angle

Program for Arc Length from Given Angle

In the previous article, we have discussed Python Program to Find Area of a Circular Segment
Given the diameter and angle of the circle, the task is to calculate the arclength from the given angle.

An angle is a geometrical figure formed when two rays intersect at the same point on a plane. These rays form the angle’s sides, and the point where they intersect is known as the angle’s vertex. It is important to remember that the plane that forms an angle does not have to be a Euclidean plane. The length of an arc in a circle is now a fraction of the circumference.

Formula:

ArcLength = ( 2 * pi * radius ) * ( angle / 360 )

diameter = 2* radius

The angle is given in degrees.

Note: It should be noted that if the angle is greater than or equal to 360 degrees, the arc length cannot be calculated because no angle is possible.

Examples:

Example1:

Input:

Given diameter = 15
Given Angle = 60

Output:

The arc length for the given angle { 60 } degrees =  7.857142857142856

Example2:

Input:

Given diameter = 30
Given Angle = 90

Output:

The arc length for the given angle { 90 } degrees =  23.57142857142857

Program for Arc Length from Given Angle in Python

Below are the ways to calculate the arc length from the given angle in python:

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Import math module using the import keyword.
  • Give the diameter as static input and store it in a variable.
  • Give the angle as static input and store it in another variable.
  • Check if the given angle is greater than or equal to 360 degrees or not using the if conditional statement.
  • If it is true, then print “The Arc length cannot be calculated for the given angle”.
  • Else, calculate the arc length using the above given mathematical formula and store it in a variable.
  • Print the arclength of the circle from the given angle.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the diameter as static input and store it in a variable.
gvn_diametr = 15
# Give the angle as static input and store it in another variable.
gvn_angl = 60
# Check if the given angle is greater than or equal to 360 degrees or not using the
# if conditional statement.
if gvn_angl >= 360:
    # If it is true, then print "The Arc length cannot be calculated for
    # the given angle".
    print("The Arc length cannot be calculated for the given angle.")
else:
    # Else, calculate the arc length using the above given mathematical formula and
    # store it in a variable.
    arc_lengt = (3.142857142857143 * gvn_diametr) * (gvn_angl / 360.0)
    # Print the arclength of the circle from the given angle.
    print("The arc length for the given angle {",
          gvn_angl, "} degrees = ", arc_lengt)

Output:

The arc length for the given angle { 60 } degrees =  7.857142857142856

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Import math module using the import keyword.
  • Give the diameter as user input using the float(input()) function and store it in a variable.
  • Give the angle as user input using the float(input()) function and store it in another variable.
  • Check if the given angle is greater than or equal to 360 degrees or not using the if conditional statement.
  • If it is true, then print “The Arc length cannot be calculated for the given angle”.
  • Else, calculate the arc length using the above given mathematical formula and store it in a variable.
  • Print the arclength of the circle from the given angle.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the diameter as user input using the float(input()) function and 
# store it in a variable.
gvn_diametr = float(input("Enter some Random Number = "))
# Give the angle as user input using the float(input()) function and store it in another variable.
gvn_angl = float(input("Enter some Random Number = "))
# Check if the given angle is greater than or equal to 360 degrees or not using the
# if conditional statement.
if gvn_angl >= 360:
    # If it is true, then print "The Arc length cannot be calculated for
    # the given angle".
    print("The Arc length cannot be calculated for the given angle.")
else:
    # Else, calculate the arc length using the above given mathematical formula and
    # store it in a variable.
    arc_lengt = (3.142857142857143 * gvn_diametr) * (gvn_angl / 360.0)
    # Print the arclength of the circle from the given angle.
    print("The arc length for the given angle {",
          gvn_angl, "} degrees = ", arc_lengt)

Output:

Enter some Random Number = 30
Enter some Random Number = 90
The arc length for the given angle { 90.0 } degrees = 23.57142857142857

Practice Python Program Examples to master coding skills and learn the fundamental concepts in the dynamic programming language Python.

Python Program to Find the Center of the Circle using Endpoints of Diameter

Program to Find the Center of the Circle using Endpoints of Diameter

In the previous article, we have discussed Python Program for Area of Square Circumscribed by Circle
Given two endpoints (x1, y1) and (x2, y2) of circles diameter, the task is to find the center of the circle for the given diameter endpoints in python.

Formula:

The center of the circle can be calculated by using the midpoint formula.

Midpoint(M) = ((x 1 + x 2) / 2, (y 1 + y 2) / 2)

Examples:

Example1:

Input:

Given First Point = ( 2, 4 ) 
Given Second Point = ( 6, -1)

Output:

The center of the circle for the given diameter endpoints is:
( 4 , 1 )

Example2:

Input:

Given First Point = ( 5, 2 )
Given Second Point = ( 1, 4 )

Output:

The center of the circle for the given diameter endpoints is:
( 3 , 3 )

Program to Find the Center of the Circle using Endpoints of Diameter in Python

Below are the ways to find the center of the circle for the given diameter endpoints in python:

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Give the first point as static input and store it in two variables.
  • Give the second point as static input and store it in another two variables.
  • Pass the given two endpoints of a diameter i.e, a1, a2, b1, b2 as the arguments to the FindCircle_Center() function.
  • Create a function to say FindCircle_Center() which takes the given two endpoints of a diameter of circle i.e, a1, a2, b1, b2 as the arguments, and prints the center of the given circle.
  • Calculate the x coordinate of the center of the given circle using the above given mathematical formula and store it in a variable.
  • Calculate the y coordinate of the center of the given circle using the above given mathematical formula and store it in another variable.
  • Print the center of the circle for the given diameter endpoints.
  • The Exit of the Program.

Below is the implementation:

# Create a function to say FindCircle_Center() which takes the given two endpoints of
# a diameter of circle i.e, a1, a2, b1, b2 as the arguments, and prints the center
# of the given circle.


def FindCircle_Center(a1, a2, b1, b2):
    # Calculate the x coordinate of the center of the given circle using the above
    # given mathematical formula and store it in a variable.

    mid_x_Coordinate = int((a1 + a2) / 2)
    # Calculate the y coordinate of the center of the given circle using the above given
    # mathematical formula and store it in another variable.

    mid_y_Coordinate = int((b1 + b2) / 2)
    # Print the center of the circle for the given diameter endpoints.
    print("(", mid_x_Coordinate, ",", mid_y_Coordinate, ")")


# Give the first point as static input and store it in two variables.
a1 = 2
b1 = 4
# Give the second point as static input and store it in another two variables.
a2 = 6
b2 = -1
print("The center of the circle for the given diameter endpoints is:")
# Pass the given two endpoints of a diameter i.e, a1, a2, b1, b2 as the arguments to the
# FindCircle_Center() function.
FindCircle_Center(a1, a2, b1, b2)

Output:

The center of the circle for the given diameter endpoints is:
( 4 , 1 )

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Give the first point as user input using map(),int(),split() functions and store it in two variables.
  • Give the second point as user input using map(),int(),split() functions and store it in two variables.
  • Pass the given two endpoints of a diameter i.e, a1, a2, b1, b2 as the arguments to the FindCircle_Center() function.
  • Create a function to say FindCircle_Center() which takes the given two endpoints of a diameter of circle i.e, a1, a2, b1, b2 as the arguments, and prints the center of the given circle.
  • Calculate the x coordinate of the center of the given circle using the above given mathematical formula and store it in a variable.
  • Calculate the y coordinate of the center of the given circle using the above given mathematical formula and store it in another variable.
  • Print the center of the circle for the given diameter endpoints.
  • The Exit of the Program.

Below is the implementation:

# Create a function to say FindCircle_Center() which takes the given two endpoints of
# a diameter of circle i.e, a1, a2, b1, b2 as the arguments, and prints the center
# of the given circle.


def FindCircle_Center(a1, a2, b1, b2):
    # Calculate the x coordinate of the center of the given circle using the above
    # given mathematical formula and store it in a variable.

    mid_x_Coordinate = int((a1 + a2) / 2)
    # Calculate the y coordinate of the center of the given circle using the above given
    # mathematical formula and store it in another variable.

    mid_y_Coordinate = int((b1 + b2) / 2)
    # Print the center of the circle for the given diameter endpoints.
    print("(", mid_x_Coordinate, ",", mid_y_Coordinate, ")")


# Give the first point as user input using map(),int(),split() functions
# and store it in two variables.
a1, b1 = map(int, input(
    'Enter some random first point values separated by spaces = ').split())
# Give the second point as user input using map(),int(),split() functions
# and store it in two variables.
a2, b2 = map(int, input(
    'Enter some random second point values separated by spaces = ').split())
print("The center of the circle for the given diameter endpoints is:")
# Pass the given two endpoints of a diameter i.e, a1, a2, b1, b2 as the arguments to the
# FindCircle_Center() function.
FindCircle_Center(a1, a2, b1, b2)

Output:

Enter some random first point values separated by spaces = 5 2
Enter some random second point values separated by spaces = 1 4
The center of the circle for the given diameter endpoints is:
( 3 , 3 )

Find a comprehensive collection of Examples of Python Programs ranging from simple ones to complex ones to guide you throughout your coding journey.

Python Program for Area of Square Circumscribed by Circle

Program for Area of Square Circumscribed by Circle

In the previous article, we have discussed Python Program for Area of a Circumscribed Circle of a Square
Given the radius of the circle, the task is to calculate the area of a square circumscribed by the circle.

Formula:

The formula to find the area of a square circumscribed by the circle = 2*(radius**2)

Where ** indicates power value

Examples:

Example1:

Input:

Given radius = 8

Output:

The area of a square circumscribed by the circle for the given radius{ 8 } =  128

Example2:

Input:

Given radius = 5

Output:

The area of a square circumscribed by the circle for the given radius{ 5 } =  50

Program for Area of Square Circumscribed by Circle in Python

Below are the ways to calculate the area of a square circumscribed by the circle in Python:

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Give the radius as static input and store it in a variable.
  • Create a function to say Areacircumscribd_square() which takes the given radius of the circle as an argument, and returns the area of a square circumscribed by the circle.
  • Inside the function, calculate the area of a square circumscribed by the circle using the above mathematical formula and store it in a variable.
  • Return the above result.
  • Pass the given radius as an argument to the Areacircumscribd_square() 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 Areacircumscribd_square() which takes the given radius of
# the circle as an argument, and returns the area of a square circumscribed
# by the circle.


def Areacircumscribd_square(gvn_radiuss):
    # Inside the function, calculate the area of a square circumscribed by the circle
    # using the above mathematical formula and store it in a variable.
    area_squar = (2 * gvn_radiuss * gvn_radiuss)
    # Return the above result.
    return area_squar


# Give the radius as static input and store it in a variable.
gvn_radiuss = 8
# Pass the given radius as an argument to the Areacircumscribd_square() function and
# store it in another variable.
fnl_rsltarea = Areacircumscribd_square(gvn_radiuss)
# Print the above result by rounding off to the 2 places after the decimal point
# using the round() function.
print("The area of a square circumscribed by the circle for the given radius{", gvn_radiuss, "} = ", round(
    fnl_rsltarea, 2))

Output:

The area of a square circumscribed by the circle for the given radius{ 8 } =  128

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Give the radius as user input using the float(input()) function and store it in a variable.
  • Create a function to say Areacircumscribd_square() which takes the given radius of the circle as an argument, and returns the area of a square circumscribed by the circle.
  • Inside the function, calculate the area of a square circumscribed by the circle using the above mathematical formula and store it in a variable.
  • Return the above result.
  • Pass the given radius as an argument to the Areacircumscribd_square() 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 Areacircumscribd_square() which takes the given radius of
# the circle as an argument, and returns the area of a square circumscribed
# by the circle.


def Areacircumscribd_square(gvn_radiuss):
    # Inside the function, calculate the area of a square circumscribed by the circle
    # using the above mathematical formula and store it in a variable.
    area_squar = (2 * gvn_radiuss * gvn_radiuss)
    # Return the above result.
    return area_squar


# Give the radius as user input using the float(input()) function and store it in a variable.
gvn_radiuss = float(input("Enter some random number = "))
# Pass the given radius as an argument to the Areacircumscribd_square() function and
# store it in another variable.
fnl_rsltarea = Areacircumscribd_square(gvn_radiuss)
# Print the above result by rounding off to the 2 places after the decimal point
# using the round() function.
print("The area of a square circumscribed by the circle for the given radius{", gvn_radiuss, "} = ", round(
    fnl_rsltarea, 2))

Output:

Enter some random number = 5
The area of a square circumscribed by the circle for the given radius{ 5.0 } = 50.0

Find the best practical and ready-to-use Python Programming Examples that you can simply run on a variety of platforms and never stop learning.