# Python Program to calculate the volume and area of the Cylinder

In this article, we will look into a python program to calculate the volume and area of a cylinder.

A cylinder is defined as a 3D object that has two circles connected with a rectangular surface. The special thing about a cylinder is that even though it is measured using just two dimensions, i.e. the height and radius, the cylinder is considered a three-dimensional figure as it is measured in xyz coordinate axes.

The area of the cylinder is calculated is two ways− area of the lateral surface and area of the total surface. Lateral surface area is only the area of the rectangular surface connecting the base circles while the total surface area is the area of the entire cylinder.

Volume of a cylinder is defined as the space contained by the said object.

Mathematical Formulae of to calculate surface areas of the cylinder are as follows −

Lateral Surface Area: 2πrh
Total Surface Area: 2πr(r + h)


The volume of a cylindrical object is calculated using the following formula −

Volume: πr2h


## Input Output Scenarios

The python program to calculate the surface areas and volume of the cylindrical object will provide the following input-output scenarios −

Assume the height and radius of the cylinder as shown below, the output is obtained as −

Input: (6, 5) // 6 is the height and 5 is the radius
Result: Lateral Surface Area of the cylinder: 188.49555921538757
Total Surface Area of the cylinder: 345.57519189487726
Volume of the cylinder: 471.2388980384689


## Using Mathematical Formulae

The standard mathematical formulae are applied to calculate the area and volume of the cylinder. We require the values of height and radius of the cylinder to substitute them in the formulae and obtain the surface areas and volume of the 3D object.

### Example

In the example code below, we import the math library from python to use the pi constant while solving for the area and volume. The inputs are considered as the height and radius of the cylindrical figure.

import math

#height and radius of the cylinder
height = 6

#calculating the lateral surface area

#calculating the total surface area

#calculating the volume

#displaying the area and volume
print("Lateral Surface Area of the cylinder: ", str(cyl_lsa))
print("Total Surface Area of the cylinder: ", str(cyl_tsa))
print("Volume of the cylinder: ", str(cyl_volume))


### Output

After executing the code above, the output is displayed as −

Lateral Surface Area of the cylinder: 188.49555921538757
Total Surface Area of the cylinder: 345.57519189487726
Volume of the cylinder: 471.23889803846896


## Function to Calculate Area and Volume

We can also make use of the user-defined functions in python to compute the area and volume. These functions in python are declared using the def keyword, with arguments passed being height and radius of the cylinder. Let us look at the example below.

### Example

The following python program makes use of function to compute the surface areas and volume of cylinder.

import math

#calculating the lateral surface area
print("Lateral Surface Area of the cylinder: ", str(cyl_lsa))

#calculating the total surface area
print("Total Surface Area of the cylinder: ", str(cyl_tsa))

#calculating the volume

#displaying the area and volume
print("Volume of the cylinder: ", str(cyl_volume))

#height and radius of the cylinder
height = 7

Lateral Surface Area of the cylinder: 175.92918860102841