Python Practice › Basic Programs › Program 16

Area of a circle

EasyBasic Programs · 16 of 40

Write a Python program to calculate the area of a circle. Area = π × r².

Advertisement
Input
r = 7
Output
Area: 153.94

Approach

  1. Use math.pi for an accurate value of π.
  2. Multiply π by the radius squared.

Solution

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

More basic programs

← All 40 Basic Programs

Leave a Comment