PythonMastery

Area of a circle program in Python

Read the radius, calculate the area with math.pi × r², and print it rounded to two decimal places. Also calculates the circumference.

The area of a circle is π × r², where r is the radius. Python's math module has an accurate value of π.

The program

python
import math

radius = float(input("Radius: "))

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

print(f"Area = {area:.2f}")
print(f"Circumference = {circumference:.2f}")

Typed in this example: 5. Press Run to type your own.

output
Radius: 5
Area = 78.54
Circumference = 31.42

How it works

Learn the idea: Numbers in Depth: Integers, Floats, and the math Module, F-Strings: Modern String Formatting