Python Program to Find the Area of a Circle
Beginner · Basics
The area of a circle is the space inside it, found with the formula area = pi x r x r, where r is the radius and pi is about 3.14159. This program uses the exact value of pi from the math module and also prints the circumference, 2 x pi x r.
Program
Radius: 7 cm Area: 153.94 square cm Circumference: 43.98 cm
How it works
import mathgives access tomath.pi, which holds pi to 15 decimal places.radius ** 2squares the radius, and multiplying bymath.pigives the area.2 * math.pi * radiusgives the circumference, the distance around the circle.:.2frounds both results to two decimal places.
Another way to write it
Using 22/7 for pi
Area of the circle: 154.00 square cm
Many textbooks use 22/7 as an approximation of pi. With a radius of 7 it gives a neat 154, slightly more than the exact 153.94.
Try it yourself
Change the program to find the radius of a circle whose area is 100 square cm, using math.sqrt().
Edit the program above and press Run, or open it in the full editor to save it and share it. To watch it run line by line, open it in the visualizer.
For a practical file: draw its flowchart or write its algorithm in steps.
Related programs
All Python programs · CBSE class 12 practical file · Python exercises