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


This Python code calculates and prints various properties of a cylinder based on user input. Here's an explanation of each part of the code:

  • import math: This line imports the math module, which provides various mathematical functions and constants.
  • radius = float(input("Enter the Radius of the Cylinder : ")): This line prompts the user to enter the radius of the cylinder and stores it as a floating-point number in the variable radius.
  • height = float(input("Enter the Height of the Cylinder : ")): This line prompts the user to enter the height of the cylinder and stores it as a floating-point number in the variable height.
  • volume = math.pi * radius**2 * height: This line calculates the volume of the cylinder using the formula for the volume of a cylinder, which is π * r^2 * h, where π is a constant (math.pi), r is the radius, and h is the height. The result is stored in the variable volume.
  • lateral_surface_area = 2 * math.pi * radius * height: This line calculates the lateral surface area of the cylinder using the formula for the lateral surface area, which is 2πrh, where π is a constant (math.pi), r is the radius, and h is the height. The result is stored in the variable lateral_surface_area.
  • total_surface_area = (2 * math.pi * radius**2) + lateral_surface_area: This line calculates the total surface area of the cylinder by summing the areas of the two circular bases (2πr^2) and the lateral surface area. The result is stored in the variable total_surface_area.
  • The code then uses print statements to display the calculated values of the volume, lateral surface area, and total surface area, along with appropriate units of measurement (cubic units and square units).

Source Code

import math
 
# Input the radius and height of the cylinder
radius = float(input("Enter the Radius of the Cylinder : "))
height = float(input("Enter the Height of the Cylinder : "))
 
# Calculate the volume of the cylinder
volume = math.pi * radius**2 * height
 
# Calculate the lateral surface area of the cylinder
lateral_surface_area = 2 * math.pi * radius * height
 
# Calculate the total surface area of the cylinder
total_surface_area = (2 * math.pi * radius**2) + lateral_surface_area
 
# Display the calculated volume, lateral surface area, and total surface area
print("Volume of the Cylinder : ",volume,"cubic units")
print("Lateral surface area of the Cylinder : ",lateral_surface_area,"square units")
print("Total surface area of the Cylinder : ",total_surface_area,"square units")

Output

Enter the Radius of the Cylinder : 2.4
Enter the Height of the Cylinder : 3
Volume of the Cylinder :  54.28672105403163 cubic units
Lateral surface area of the Cylinder :  45.23893421169302 square units
Total surface area of the Cylinder :  81.43008158104743 square units

Example Programs