Surface area of a cylinder
Write a Python program to calculate the surface area of a cylinder. Area = 2πrh + 2πr².
r = 3, h = 10
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))Surface area: 245.04
Line by line
Splitting the formula into named parts makes each step easy to check.
The total is rounded to two decimals.
Learn the concept
New to this topic? Read the lesson, then come back.