Python Practice › Basic Programs › Program 16
Area of a circle
Write a Python program to calculate the area of a circle. Area = π × r².
Input
r = 7
Output
Area: 153.94
Approach
- Use
math.pifor an accurate value of π. - Multiply π by the radius squared.
Solution
import math r = 7area = math.pi * r ** 2print("Area:", round(area, 2))Output
Area: 153.94
Line by line
Line 4
math.pi is π to 15 decimal places, more accurate than 3.14.
Line 5
round(area, 2) keeps two decimals for display.
Learn the concept
New to this topic? Read the lesson, then come back.