How to do calculate area of a circle in Python

Python PythonBasic

In this post, we are going to learn How to calculate the area of a circle in Python with some code and math modules.

1. Python Program to Find area of circle


To find the area of the circle we taking the circle radius input from the user using the input() method and convert the input to float using the float() method, pi has constant value so store it in variable pi.

  • The formula to calculate area of circle is = πr2
  • where π is pi
  • r2 is radius * radius

Python Program

Pi = 3.14
Redius = float(input("Enter a  circle radius :"))
circle_area = Pi * Redius * Redius
print("Calculated area of a circle = %.2f" %circle_area)

Output

Enter a  circle radius :12
Calculated area of a circle = 452.16

2. Python Find area of circle Using Function


We have defined a custom function cal_circle_area() with a two-parameter to find the area of a circle.

Python Program to calculate area of circle

Pi = 3.14
Redius = float(input("Enter a  circle radius :"))

def cal_circle_area(Pi,radius):
   return Pi * (radius*radius);

   
print("Calulcated Area of circle = %.3f" % cal_circle_area(Pi,Redius));
 

Output

Enter a  circle radius :12.5
Area of circle = 490.625

3. Math Module to Find area of a circle in Python


Instead of custom code, we can use the inbuilt python math module to calculate the area of a circle in Python.

Python Program Example

import math

Redius = float(input("Enter a  circle radius :"))

cicle_area = math.pi * Redius * Redius
   
print("Calulcated Area of circle = %.3f" %cicle_area);
 

Output

Enter a  circle radius :13.5
Calulcated Area of circle = 572.555

4. Python Program to Find area of circle using circumferce


Sometimes instead of a radius, we have a circumference of the circle. The circumference is the distance around the outside of the circle. We are using an inbuilt math module to calculate the area using circumference.

  • The formaula to caluculate the area of circle using circumferce is = C²⁄ 4π.
  • : Is the circumferce of circle
  • π : The value of pi.

Python Program

import math

circum = float(input("Enter a circle circumference :"))

area = (circum * circum)/(4 * math.pi)

print(" calcualted area Of a Circle = %.2f" %area)


Output

Enter a circle circumference :30
 calcualted area Of a Circle = 71.62

5. Find area of circle using Diameter


Sometimes we have to calculate the area of the circle from Diameter. The diameter is twice the length of the radius of the circle, we are using the math module for this.

  • The formaula to calculate the area of circle using Diameter is Area_of_circle =π/4*D²
  • π is the value of pi
  • is diameter of circle = diameter * diameter

Python Program to Find area of circle using Diameter

import math

diameter = float(input("Enter a circle Diameter :"))

Circle_area = (math.pi/4) * (diameter * diameter)

print(" calcualted area Of a Circle = %.2f" %Circle_area)

Output

Enter a circle Diameter :5
 calcualted area Of a Circle = 19.63

6. Find area and circumference diameter of circle


In this example, we are calculating the area circumference diameter of the circle by using the simple code. We are taking radius input() from the user. The formula for these are:

  • Formula to find area of circle = pi * Redius * Redius
  • Formula to find circumference of circle = 2 * pi * Redius
  • Formula to find diameter of circle = 2*Redius

Program to calculate circle area circumference diameter

pi = 3.14
Redius = float(input("Enter a  circle radius :"))

circle_area = pi * Redius * Redius
circle_circum = 2 * pi * Redius
circle_diameter = 2*Redius 
   
print("Calulcated Area of circle = %.3f" %circle_area)


print(" Calculate Circumference Of a Circle = %.3f" %circle_circum)
print(" Calculated  Diameter Of a Circle =%.3f" % circle_diameter )


 

Output

Enter a  circle radius :6.9
Calulcated Area of circle = 149.495
 Calculate Circumference Of a Circle = 43.332
 Calculated  Diameter Of a Circle =13.800

7.Math Module to Find area circumference Diameter of circle


This is an alternative to the above code instead of using hard code pi value the python math module can be used to Find the area circumference Diameter of the circle.

Python Program

import math

Redius = float(input("Enter a  circle radius :"))

circle_area = math.pi * Redius * Redius
circle_circum = 2 * math.pi * Redius
circle_diameter = 2*Redius 
print('calculated area of circle:%.3f' % circle_area)
print(" Calculated  circumference Of a Circle =%.3f" % circle_circum)
print(" Calculated  Diameter Of a Circle =%.3f" % circle_diameter )



Output

Enter a  circle radius :6.9
calculated area of circle:149.571
 Calculated  circumference Of a Circle =43.354
 Calculated  Diameter Of a Circle =13.800

8. Python Program to Find area and primeter of a circle


In this example, we are finding the Find area and perimeter of a circle by taking input from the user.

Python Program

pi = 3.14
Redius = float(input("Enter a  circle radius :"))

circle_area = pi * Redius * Redius
circle_perimeter = 2 * pi * Redius
   
print("Calulcated Area of circle = ",circle_area)


print(" Calculated perimeter Of a Circle = ", circle_perimeter)


Output

Enter a  circle radius :9.6
Calulcated Area of circle =  289.38239999999996
 Calculated perimeter Of a Circle =  60.288

Summary

In this post, we have learned multiple ways of how to find the area of a circle in python we can use any of the above methods as per need to calculate the area of circles in Python.