# Python program to calculate surface area and volume of a cylinder

In this program, we are going to learn how we can **calculate the surface area and volume of the cylinder in python**.

## How to calculate the area and volume of the cylinder in Python

A cylinder is a geometrical closed solid shape that has two parallel bases connected by a curved surface.

The shape of the bases is the circle.

The formula for area of a cylinder:

Surface area = 2πr(r+h) where r--> radious of base circle and h is the height of the curve surface.

The formula for the volume of a cylinder:

Volume of cylinder=πr²h where r--> radious of base circle and h is the height of the curve surface.

now move on to the coding part:

we have to 1st import the math package to use the value of PI.

#impotr math package to use math.pi for the value of PI import math

Take the user input radius and height of the cylinder:

#take radius of the base of a cylinder from user r=float(input("Enter radius of a cylinde")) #take height of the curve surface of a cylinder from user h=float(input("Enter the Height of a cylinder"))

now calculate the surface area and volume of the cylinder by the help of the above formula:

#calculate the surface area of cylinder s_area=2*math.pi*pow(r,2)*h #calculate the volume of cylinder volume=math.pi*pow(r,2)*h

now combine the whole part of the program in a single window.

#impotr math package to use math.pi for the value of PI import math #take radius of the base of a cylinder from user r=float(input("Enter r of a cylinde")) #take height of the curve surface of a cylinder from user h=float(input("Enter the Height of a cylinde")) #calculate the surface area of cylinder s_area=2*math.pi*pow(r,2)*h #calculate the volume of cylinder volume=math.pi*pow(r,2)*h print("surface area of a cylinder wll be %.2f" %s_area) print("volume of a cylinder will be %.2f" %volume)

Output:

Enter the Radius of a cylinder: 5 Enter the Height of a cylinder: 6 surface area of a cylinder wll be 942.48 volume of a cylinder will be 471.24

We hope now you understood how to calculate surface area and volume of a cylinder in Python.

You may also read,

## Leave a Reply