This Python program calculates both the volume and the lateral surface area of a cylinder.
It prompts the user to enter the radius and height, then uses mathematical formulas to compute and display the results.
The code is formatted for seamless integration into a webpage using the specified HTML structure.
import math
radius = float(input("Please enter the radius of the cylinder: "))
height = float(input("Please enter the height of the cylinder: "))
volume = math.pi * radius ** 2 * height
surface_area = 2 * math.pi * radius * height
print("Volume of the cylinder is:", volume)
print("Lateral surface area of the cylinder is:", surface_area)
Please enter the radius of the cylinder: 3
Please enter the height of the cylinder: 5
Volume of the cylinder is: 141.3716694115407
Lateral surface area of the cylinder is: 94.24777960769379
Here's how the program works:
- It uses the math
module to access the constant pi
.
- The volume is calculated using the formula π × r² × h
.
- The lateral surface area is calculated using 2 × π × r × h
.
- The results are printed using the print()
function.