Python Program for Volume and Surface Area of Frustum of Cone

In the previous article, we have discussed Python Program for lgamma() Function
Given the height, slant height, smaller and bigger radius of a frustum cone, the task is to find the volume and surface area of the frustum of a given cone in python.

Frustum of a Cone :

A frustum in geometry is the portion of a solid (typically a cone or pyramid) that lies between one or two parallel planes that cut it.
The portion of a solid between a plane parallel to the base and a right circular cone is known as the frustum of a cone.

A right circular cone is shown below:

After being cut by a plane parallel to its base, the right circular cone produces the following frustum:

which has a circular base with radius R at the bottom, a circular upper portion with radius R height h, and a slant height l.

Formulas:

volume of the frustum of a cone = 1/3 * pi * h(r2 + R2 + r*R)

The curved surface area of a frustum of a cone = pi * l(R+r)

The total surface area of a frustum of a cone = pi * l(R+r) + pi(R2 + r2)

In which,

r is the radius of the smaller circle

R is the radius of the bigger circle

l is the slant height of the frustum of a cone.

Examples:

Example1:

Input:

Given smaller radius = 3
Given bigger radius = 6
Given slant height = 8
Given height  = 10

Output:

The Volume of above given Frustum of Cone =  659.7344572538565
The curved surface area of the above given frustum of Cone =  226.1946710584651
The total surface area of the above given frustum of Cone :  367.5663404700058

Example2:

Input:

Given smaller radius = 4
Given bigger radius = 7
Given slant height = 10
Given height = 15

Output:

The Volume of above given Frustum of Cone = 1460.8405839192537
The curved surface area of the above given frustum of Cone = 345.57519189487726
The total surface area of the above given frustum of Cone : 549.7787143782139

Program for Volume and Surface Area of Frustum of Cone in Python

Below are the ways to find the volume and surface area of the frustum of a given cone in python:

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Import math module using the import keyword.
  • Get the value of pi using the math.pi function and store it in a variable.
  • Give the radius of the smaller circle as static input and store it in a variable.
  • Give the radius of the bigger circle as static input and store it in another variable.
  • Give the slant height of the frustum cone as static input and store it in another variable.
  • Give the height as static input and store it in another variable.
  • Calculate the volume of the frustum of a cone using the above given mathematical formula and store it in another variable.
  • Calculate the curved surface area of a frustum of a cone using the above given mathematical formula and store it in another variable.
  • Calculate the total surface area of a frustum of a cone using the above given mathematical formula and store it in another variable.
  • Print the volume of the frustum of a cone.
  • Print the curved surface area of a frustum of a cone.
  • Print the Total surface area of a frustum of a cone.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Get the value of pi using the math.pi function and store it in a variable.
pi_val = math.pi
# Give the radius of the smaller circle as static input and store it in a variable.
gvn_smallrradiuss = 3
# Give the radius of the bigger circle as static input and store it in another variable.
gvn_biggradiuss = 6
# Give the slant height of the frustum cone as static input and store it in
# another variable.
gvn_slantheigt = 8
# Give the height as static input and store it in another variable.
gvn_heigt = 10
# Calculate the volume of the frustum of a cone using the above given mathematical
# formula and store it in another variable.
rslt_vol = 1 / 3 * pi_val * gvn_heigt * \
    (gvn_smallrradiuss * gvn_smallrradiuss + gvn_biggradiuss *
     gvn_biggradiuss + gvn_smallrradiuss * gvn_biggradiuss)
# Calculate the curved surface area of a frustum of a cone using the above given
# mathematical formula and store it in another variable.
curvd_surfce_area = pi_val * gvn_slantheigt * \
    (gvn_biggradiuss + gvn_smallrradiuss)
# Calculate the total surface area of a frustum of a cone using the above given
# mathematical formula and store it in another variable.
totl_surfce_area = pi_val * gvn_slantheigt * (gvn_biggradiuss + gvn_smallrradiuss) + pi_val * \
    (gvn_smallrradiuss * gvn_smallrradiuss + gvn_biggradiuss * gvn_biggradiuss)
# Print the volume of the frustum of a cone.
print("The Volume of above given Frustum of Cone = ", rslt_vol)
# Print the curved surface area of a frustum of a cone.
print("The curved surface area of the above given frustum of Cone = ", curvd_surfce_area)
# Print the Total surface area of a frustum of a cone.
print("The total surface area of the above given frustum of Cone : ", totl_surfce_area)
#include <cmath>
#include <iostream>

using namespace std;

int main()
{
    int argc = 2;
    double pi_val = M_PI;
    double gvn_smallrradiuss = 3;
    int gvn_biggradiuss = 6;
    int gvn_slantheigt = 8;
    int gvn_heigt = 10;
    double rslt_vol
        = 1 / 3 * pi_val * gvn_heigt
          * (gvn_smallrradiuss * gvn_smallrradiuss
             + gvn_biggradiuss * gvn_biggradiuss
             + gvn_smallrradiuss * gvn_biggradiuss);
    double curvd_surfce_area
        = pi_val * gvn_slantheigt
          * (gvn_biggradiuss + gvn_smallrradiuss);
    double totl_surfce_area
        = pi_val * gvn_slantheigt
              * (gvn_biggradiuss + gvn_smallrradiuss)
          + pi_val * gvn_smallrradiuss * gvn_smallrradiuss
          + gvn_biggradiuss * gvn_biggradiuss;
    // Print the volume of the frustum of a cone.
    cout << "The Volume of above given Frustum of Cone = "
         << rslt_vol << endl;
    // Print the curved surface area of a frustum of a cone.
    cout << "The curved surface area of the above given "
            "frustum of Cone = "
         << curvd_surfce_area << endl;
    // Print the Total surface area of a frustum of a cone.
    cout << "The total surface area of the above given "
            "frustum of Cone :"
         << totl_surfce_area;
}

Output:

The Volume of above given Frustum of Cone =  659.7344572538565
The curved surface area of the above given frustum of Cone =  226.1946710584651
The total surface area of the above given frustum of Cone :  367.5663404700058

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Import math module using the import keyword.
  • Get the value of pi using the math.pi function and store it in a variable.
  • Give the radius of the smaller circle as user input using the float(input()) function and store it in a variable.
  • Give the radius of the bigger circle as user input using the float(input()) function and store it in another variable.
  • Give the slant height of the frustum cone as user input using the float(input()) function and store it in another variable.
  • Give the height as user input using the float(input()) function and store it in another variable.
  • Calculate the volume of the frustum of a cone using the above given mathematical formula and store it in another variable.
  • Calculate the curved surface area of a frustum of a cone using the above given mathematical formula and store it in another variable.
  • Calculate the total surface area of a frustum of a cone using the above given mathematical formula and store it in another variable.
  • Print the volume of the frustum of a cone.
  • Print the curved surface area of a frustum of a cone.
  • Print the Total surface area of a frustum of a cone.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Get the value of pi using the math.pi function and store it in a variable.
pi_val = math.pi
# Give the radius of the smaller circle as user input using the float(input()) function
# and store it in a variable.
gvn_smallrradiuss = float(input("Enter some random number = "))
# Give the radius of the bigger circle as user input using the float(input()) function 
# and store it in another variable.
gvn_biggradiuss = float(input("Enter some random number = "))
# Give the slant height of the frustum cone as user input using the float(input()) function
# and store it in another variable.
gvn_slantheigt = float(input("Enter some random number = "))
# Give the height as user input using the float(input()) function and
# store it in another variable.
gvn_heigt = float(input("Enter some random number = "))
# Calculate the volume of the frustum of a cone using the above given mathematical
# formula and store it in another variable.
rslt_vol = 1 / 3 * pi_val * gvn_heigt * \
    (gvn_smallrradiuss * gvn_smallrradiuss + gvn_biggradiuss *
     gvn_biggradiuss + gvn_smallrradiuss * gvn_biggradiuss)
# Calculate the curved surface area of a frustum of a cone using the above given
# mathematical formula and store it in another variable.
curvd_surfce_area = pi_val * gvn_slantheigt * \
    (gvn_biggradiuss + gvn_smallrradiuss)
# Calculate the total surface area of a frustum of a cone using the above given
# mathematical formula and store it in another variable.
totl_surfce_area = pi_val * gvn_slantheigt * (gvn_biggradiuss + gvn_smallrradiuss) + pi_val * \
    (gvn_smallrradiuss * gvn_smallrradiuss + gvn_biggradiuss * gvn_biggradiuss)
# Print the volume of the frustum of a cone.
print("The Volume of above given Frustum of Cone = ", rslt_vol)
# Print the curved surface area of a frustum of a cone.
print("The curved surface area of the above given frustum of Cone = ", curvd_surfce_area)
# Print the Total surface area of a frustum of a cone.
print("The total surface area of the above given frustum of Cone : ", totl_surfce_area)

Output:

Enter some random number = 4
Enter some random number = 7
Enter some random number = 10
Enter some random number = 15
The Volume of above given Frustum of Cone = 1460.8405839192537
The curved surface area of the above given frustum of Cone = 345.57519189487726
The total surface area of the above given frustum of Cone : 549.7787143782139