Python program to calculate area and circumference of a circle

This python program/script calculates and prints the area and circumference of a circle. In both the cases, the user enters the radius of the circle.

Prerequisite knowledge:

  • Value of pi is equal to the ratio of the circumference to the diameter of the circle, which is 22/7 or 3.14 as used in basic calculations.
  • Importing a module in python
  • Syntax of basic python statements.

Program #1 : Python program to calculate area and circumference using math.pi

import math       
                
radius = float(input("Enter the radius: "))       
                
area = math.pi * radius * radius       
                
cir = 2 * math.pi * radius       
                
print("Area of the circle is: %.2f" %area)    #%.2f to print upto 2 decimal places       
                
print("Circumference of the circle is: %.2f" %cir)

Output:

Enter the radius: 9
Area of the circle is: 254.47
Circumference of the circle is: 56.55

Program #2 – Python program to calculate area and circumference using PI object

PI = 3.14       
                
radius = float(input("Enter the radius: "))       
                
area = PI * radius * radius       
                
cir = 2 * PI * radius       
                
print("Area of the circle is: %.2f" %area)       
                
print("Circumference of the circle is: %.2f" %cir)  

Output:

Enter the radius: 8
Area of the circle is: 200.96
Circumference of the circle is: 50.27

If you have any queries, let us know in the comments.

About ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ

Linux and Python enthusiast, in love with open source since 2014, Writer at programming-articles.com, India.

View all posts by ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ →

Leave a Reply

Your email address will not be published. Required fields are marked *