Python Practice › Basic Programs › Program 18
Surface area of a cylinder
Write a Python program to calculate the surface area of a cylinder. Area = 2πrh + 2πr².
Input
r = 3, h = 10
Output
Surface area: 245.04
Approach
- Curved surface = 2πrh; the two circular ends = 2πr².
- Add them.
Solution
import math r = 3h = 10curved = 2 * math.pi * r * hends = 2 * math.pi * r ** 2print("Surface area:", round(curved + ends, 2))Output
Surface area: 245.04
Line by line
Lines 5-6
Splitting the formula into named parts makes each step easy to check.
Line 7
The total is rounded to two decimals.
Learn the concept
New to this topic? Read the lesson, then come back.