Home / Python / Example programs / Basics

Python program: Area and circumference of a circle

Given a radius, calculate the area (πr²) and circumference (2πr).

The code

import math

radius = 4.5
area = math.pi * radius ** 2
circumference = 2 * math.pi * radius

print(f"radius {radius}: area {area:.2f}, circumference {circumference:.2f}")

Output

radius 4.5: area 63.62, circumference 28.27

How it works

math.pi is π to 15 decimal places; ** raises to a power; :.2f shows 2 decimals.

Python features used

Learn the ideas behind it in the free lesson Modules & the Standard Library.