Python Practice › Basic Programs › Program 18

Surface area of a cylinder

EasyBasic Programs · 18 of 40

Write a Python program to calculate the surface area of a cylinder. Area = 2πrh + 2πr².

Advertisement
Input
r = 3, h = 10
Output
Surface area: 245.04

Approach

  1. Curved surface = 2πrh; the two circular ends = 2πr².
  2. Add them.

Solution

Python
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.

More basic programs

← All 40 Basic Programs

Leave a Comment