In the previous article, we have discussed Python Program to Check Pronic Number or Not
Cylinder :
A cylinder is a closed geometrical solid shape with two parallel bases joined by a curved surface.
The bases are circular in shape.
The following is the formula for calculating
- The area of a cylinder = 2πr(r+h)
- The volume of a cylinder = πr²h
where r = radius of the base circle
h = height of the curved surface
Given the radius and height of the cylinder, and the task is to calculate the surface area and volume of the given cylinder.
Examples:
Example 1:
Input:
Given radius = 2.5 Given height = 3.5
Output:
The surface area of a given cylinder = 137.44467859455347 The volume of a given cylinder = 68.72233929727673
Example 2:
Input:
Given radius = 7 Given height = 1.5
Output:
The surface area of a given cylinder = 461.81412007769956 The volume of a given cylinder = 230.90706003884978
Program to Calculate Surface Area and Volume of a Cylinder
Below are the ways to calculate the surface area and volume of the given cylinder.
Method #1: Using Mathematical Formula (Static Input)
Approach:
- Import math module using the import keyword.
- Give the radius as static input and store it in a variable.
- Give the height as static input and store it in another variable.
- Calculate the surface area of the given cylinder using the above given mathematical formula, math.pi () method and store it in another variable.
- Calculate the volume of the given cylinder using the above given mathematical formula, math.pi () method and store it in another variable.
- Print the surface area of the given cylinder.
- Print the volume of the given cylinder.
- The Exit of the program.
Below is the implementation:
# Import math module using the import keyword. import math # Give the radius as static input and store it in a variable. gvn_radius = 4 # Give the height as static input and store it in another variable. gvn_heigt = 7 # Calculate the surface area of the given cylinder using the above given mathematical # formula, math.pi () method and store it in another variable. surfc_area = 2*math.pi*pow(gvn_radius, 2)*gvn_heigt # Calculate the volume of the given cylinder using the above given mathematical formula, # math.pi () method and store it in another variable. vol = math.pi*pow(gvn_radius, 2)*gvn_heigt # Print the surface area of the given cylinder. print("The surface area of a given cylinder =", surfc_area) # Print the volume of the given cylinder. print("The volume of a given cylinder =", vol)
Output:
The surface area of a given cylinder = 703.7167544041137 The volume of a given cylinder = 351.85837720205683
Method #2: Using Mathematical Formula (User Input)
Approach:
- Import math module using the import keyword.
- Give the radius as user input using the float(input()) function and store it in a variable.
- Give the height as user input using the float(input()) function and store it in another variable.
- Calculate the surface area of the given cylinder using the above given mathematical formula, math.pi () method and store it in another variable.
- Calculate the volume of the given cylinder using the above given mathematical formula, math.pi () method and store it in another variable.
- Print the surface area of the given cylinder.
- Print the volume of the given cylinder.
- The Exit of the program.
Below is the implementation:
# Import math module using the import keyword. import math # Give the radius as user input using the float(input())function and store it in a variable. gvn_radius = float(input("Enter some random number = ")) # Give the height as user input using the float(input())function store it in another variable. gvn_heigt = float(input("Enter some random number = ")) # Calculate the surface area of the given cylinder using the above given mathematical # formula, math.pi () method and store it in another variable. surfc_area = 2*math.pi*pow(gvn_radius, 2)*gvn_heigt # Calculate the volume of the given cylinder using the above given mathematical formula, # math.pi () method and store it in another variable. vol = math.pi*pow(gvn_radius, 2)*gvn_heigt # Print the surface area of the given cylinder. print("The surface area of a given cylinder =", surfc_area) # Print the volume of the given cylinder. print("The volume of a given cylinder =", vol)
Output:
Enter some random number = 5.5 Enter some random number = 8 The surface area of a given cylinder = 1520.53084433746 The volume of a given cylinder = 760.26542216873
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.
- Python Program to Compute the Area and Perimeter of Pentagon
- Python Program to Find Sum of Geometric Progression Series
- Python Program to Find Isosceles Triangle Area
- Python Program to Find out the Arc Length of an Angle