# Python Program to Find Volume and Surface Area of a Cone

In the previous article, we have discussed Python Program to Calculate Sum of Series 1³+2³+3³+….+n³
The surface area of a cone :

Formula to calculate its surface area:
Surface Area = Area of a Cone + Area of a Circle
i.e. Surface Area of cone = πrl + πr²
In which  ‘r’ denotes radius and

‘l’ denotes slant (Length of an edge from the top of the cone to edge of a cone)

If we know the radius and height of a cone, we can use the following formula to calculate its surface area:
Surface Area = πr² +πr √h² + r²
It can also be written as:
Surface Area of a cone =  πr (r+√h² + r²)

Because the radius, height, and slant combine to form a right-angled triangle. So, using Pythagoras’ theorem:

l² = h² + r²
l = √h² + r²

The volume of a cone :

Volume refers to the amount of space inside the Cone. If we know the radius and height of the cone, we can use the following formula to calculate the volume:
The volume of a cone= 1/3 πr²h  (where h = height of a cone)

A Cone’s Lateral Surface Area = πrl

Given the radius and height of a cone, the task is to find the surface area, volume, and lateral surface for a given cone.

Examples:

Example 1:

Input:

Given radius = 6.5
Given height = 10

Output:

The given cone's slant height = 11.927
The given surface Area of a cone with given radius,height[ 6.5 10 ]= 376.283
The given volume of a cone with given radius,height[ 6.5 10 ]= 442.441
The given lateral surface Area of a cone with given radius,height[ 6.5 10 ]= 243.551

Example 2:

Input:

Given radius =  4
Given height = 8

Output:

The given cone's slant height = 8.944
The given surface Area of a cone with given radius,height[ 4 8 ]= 162.663
The given volume of a cone with given radius,height[ 4 8 ]= 134.041
The given lateral surface Area of a cone with given radius,height[ 4 8 ]= 112.397

## Program to Find Volume and Surface Area of a Cone

Below are the ways to find the surface area, volume, and lateral surface for a given cone.

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

Approach:

• Import math module using the import keyword.
• Give the radius of a cone as static input and store it in a variable.
• Give the height of a cone as static input and store it in another variable.
• Calculate the Slant height of a given cone using the above given mathematical formula and math.sqrt() function and store it in another variable.
• Calculate the surface area of a given cone using the above given mathematical formula and math.pi function
• Store it in another variable.
• Calculate the volume of a given cone using the above given mathematical formula and math.pi function
• Store it in another variable.
• Calculate the lateral surface area of a given cone using the above given mathematical formula and math.pi function.
• Store it in another variable.
• Print the slant height of a given cone.
• Print the surface area of a given cone.
• Print the volume of a given cone.
• Print the lateral surface area of a given cone.
• The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the radius of a cone as static input and store it in a variable.
# Give the height of a cone as static input and store it in another variable.
gvn_heigt = 10
# Calculate the Slant height of a given cone using the above given mathematical formula
# and math.sqrt() function and store it in another variable.
slant_l = math.sqrt(gvn_rad * gvn_rad + gvn_heigt * gvn_heigt)
# Calculate the surface area of a given cone using the above given mathematical formula and math.pi function
# Store it in another variable.
surf_area = math.pi * gvn_rad * (gvn_rad + slant_l)
# Calculate the volume of a given cone using the above given mathematical formula and
# math.pi function
# Store it in another variable.
Vol = (1.0/3) * math.pi * gvn_rad * gvn_rad * gvn_heigt
# Calculate the lateral surface area of a given cone using the above given mathematical
# formula and math.pi function.
# Store it in another variable.
Laterl_surfcarea = math.pi * gvn_rad * slant_l
# Print the slant height of a given cone.
print("The given cone's slant height = %.3f" % slant_l)
# Print the surface area of a given cone.
print(
"The given surface Area of a cone with given radius,height[", gvn_rad, gvn_heigt, "]= %.3f" % surf_area)
# Print the volume of a given cone.
print(
"The given volume of a cone with given radius,height[", gvn_rad, gvn_heigt, "]= %.3f" % Vol)
# Print the lateral surface area of a given cone.
print(
"The given lateral surface Area of a cone with given radius,height[", gvn_rad, gvn_heigt, "]= %.3f " % Laterl_surfcarea)


Output:

The given cone's slant height = 11.927
The given surface Area of a cone with given radius,height[ 6.5 10 ]= 376.283
The given volume of a cone with given radius,height[ 6.5 10 ]= 442.441
The given lateral surface Area of a cone with given radius,height[ 6.5 10 ]= 243.551

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

Approach:

• Import math module using the import keyword.
• Give the radius of a cone as user input using the float(input()) function and store it in a variable.
• Give the height of a cone as user input using the float(input()) function and store it in another variable.
• Calculate the Slant height of a given cone using the above given mathematical formula and math.sqrt() function and store it in another variable.
• Calculate the surface area of a given cone using the above given mathematical formula and math.pi function
• Store it in another variable.
• Calculate the volume of a given cone using the above given mathematical formula and math.pi function
• Store it in another variable.
• Calculate the lateral surface area of a given cone using the above given mathematical formula and math.pi function.
• Store it in another variable.
• Print the slant height of a given cone.
• Print the surface area of a given cone.
• Print the volume of a given cone.
• Print the lateral surface area of a given cone.
• The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the radius of a cone user input using the float(input()) function and store it in a variable.
gvn_rad = float(input("Enter some random number = "))
# Give the height of a cone user input using the float(input()) function and store it in another variable.
gvn_heigt = float(input("Enter some random number = "))
# Calculate the Slant height of a given cone using the above given mathematical formula
# and math.sqrt() function and store it in another variable.
slant_l = math.sqrt(gvn_rad * gvn_rad + gvn_heigt * gvn_heigt)
# Calculate the surface area of a given cone using the above given mathematical formula and math.pi function
# Store it in another variable.
surf_area = math.pi * gvn_rad * (gvn_rad + slant_l)
# Calculate the volume of a given cone using the above given mathematical formula and
# math.pi function
# Store it in another variable.
Vol = (1.0/3) * math.pi * gvn_rad * gvn_rad * gvn_heigt
# Calculate the lateral surface area of a given cone using the above given mathematical
# formula and math.pi function.
# Store it in another variable.
Laterl_surfcarea = math.pi * gvn_rad * slant_l
# Print the slant height of a given cone.
print("The given cone's slant height = %.3f" % slant_l)
# Print the surface area of a given cone.
print(
"The given surface Area of a cone with given radius,height[", gvn_rad, gvn_heigt, "]= %.3f" % surf_area)
# Print the volume of a given cone.
print(
"The given volume of a cone with given radius,height[", gvn_rad, gvn_heigt, "]= %.3f" % Vol)
# Print the lateral surface area of a given cone.
print(
"The given lateral surface Area of a cone with given radius,height[", gvn_rad, gvn_heigt, "]= %.3f " % Laterl_surfcarea)


Output:

Enter some random number = 4.5
Enter some random number = 2
The given cone's slant height = 4.924
The given surface Area of a cone with given radius,height[ 4.5 2.0 ]= 133.235
The given volume of a cone with given radius,height[ 4.5 2.0 ]= 42.412
The given lateral surface Area of a cone with given radius,height[ 4.5 2.0 ]= 69.617

Explore more instances related to python concepts from Python Programming Examples Guide and get promoted from beginner to professional programmer level in Python Programming Language.