Python Program for Find the perimeter of a cylinder

In this article, we will learn how to calculate the perimeter of a cylinder using Python. The perimeter represents the outline of the cylinder when viewed from the side.

Understanding Cylinder Perimeter

When we view a cylinder from the side, it appears as a rectangle. The perimeter is the total distance around this rectangular outline.

diameter (d) height (h) 3D Cylinder Side View (Rectangle)

Formula

The perimeter of a cylinder's side view is calculated as ?

Perimeter = 2 × (diameter + height)

Where:

  • d is the diameter of the cylinder
  • h is the height of the cylinder

Implementation

# Function to calculate the perimeter of a cylinder
def perimeter(diameter, height):
    return 2 * (diameter + height)

# Main calculation
diameter = 5
height = 10
result = perimeter(diameter, height)
print("Perimeter =", result)
Perimeter = 30

Example with User Input

def calculate_cylinder_perimeter():
    diameter = float(input("Enter diameter: "))
    height = float(input("Enter height: "))
    
    perimeter = 2 * (diameter + height)
    
    print(f"Cylinder dimensions:")
    print(f"Diameter: {diameter}")
    print(f"Height: {height}")
    print(f"Perimeter: {perimeter}")

# Example with predefined values (for demonstration)
diameter = 8.5
height = 12.3
perimeter = 2 * (diameter + height)
print(f"For diameter {diameter} and height {height}:")
print(f"Perimeter = {perimeter}")
For diameter 8.5 and height 12.3:
Perimeter = 41.6

Conclusion

Calculating the perimeter of a cylinder involves treating its side view as a rectangle. The formula 2 × (diameter + height) gives us the total outline distance of this rectangular projection.

Updated on: 2026-03-25T06:21:37+05:30

192 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements