Online Tutorials & Training Materials | STechies.com
Register Login

Python Program to Find Area of Circle

26 Sep 2019 1:12 pm || 0

In order to find out the area of a circle in Python, you have to know the radius of the circle. The formula for determining the area of a circle is A=πr². In case you have the diameter of the circle, the formula A=1/4πd2 has to be used. There is another formula with circumference, A=c2/4π, that can be used for finding the area.

This tutorial explains how to create a simple python program to find the area of a circle. This article contains simple source codes to find out the area of a circle using circumference, diameter and radius of a circle.

Formula to Calculate Area of a Circle

With Radius

A=π (r)2

π = 22/7
r = radius of a circle

With Diameter

A=1/4πd2

π = 22/7
d = diameter of a circle

With Circumference

A=c2/4π

π = 22/7
c = circumference of a circle

Program to Find Area of Circle Using Radius

# Program to find Area of Circle using radius

# Taking radius from user
r = float(input("Enter the radious of circle : "))

# Taking radius measure unit from user
unit = input("Enter the measure unit of radius (e.g. in, cm) : ")

# Finding area of a circle using ( A = /\R*R ) formula
area = ((22/7) * (r*r))

# Print the area
print("Area of circle is : ",area,unit+"2")

OUTPUT :

Enter the radius of circle : 6.5
Enter the measure unit of radius (e.g. in, cm): m
Area of circle is : 132.78571428571428 m2

Explanation

In this program, the radius of the circle is obtained from the user. The input() method is used for this. Then the radius is converted to float using the float() method. Then the input() method is used for fetching the units of measurement from the user, that can be in cm or inches.

In the line area = ((22/7) * (r*r)) the radius is calculated. This is done by multiplying the square of the radius with the value of Pi that is 22/7. The final print() method displays the final area of the circle along with the unit of measurement.

As per the output, the user has entered 6.5 as the radius and m as the measurement unit. The calculated area of the circle is 132.78571428571428 m2.

Program to Find Area of Circle Using Diameter

# Program to find Area of Circle using Diameter

# Taking diameter from user
diameter = float(input("Enter the diameter of circle : "))

# Taking diameter measure unit from user
unit = input("Enter the measure unit of diameter (e.g. in, cm) : ")

# Finding area of a circle using ( A = 1/4 * /\ * D*D ) formula
area = ((1 / 4) * (22 / 7) * (diameter * diameter))

# Printing the area
print("Area of circle is : ",area,unit+"2")

OUTPUT :

Enter the diameter of circle : 20
Enter the measure unit of diameter (e.g. in, cm) : in
Area of circle is : 314.2857142857143 in2

Explanation

Here, the diameter of the circle is obtained from the user through the input() method. It is converted to float using the float() function and stored in the diameter variable. The unit of measurement is also obtained using input() and stored in the unit variable.

The area is determined using the code area = ((1 / 4) * (22 / 7) * (diameter * diameter)). The print() statement prints out the result. According to the output, you can see that the user has entered 20 as the diameter and in as the unit of measurement. The resultant area of the circle is 314.2857142857143 in2.

Find Area of Circle Using Circumference

# Program to find Area of Circle using Circumference

# Taking circumference  from user
circumference  = float(input("Enter the circumference  of circle : "))

# Taking circumference  measure unit from user
unit = input("Enter the measure unit of circumference  (e.g. in, cm) : ")

# Finding area of a circle using ( A = 1/4 * /\ * D*D ) formula
area = ((circumference  * circumference ) / (4 * (22 / 7) ))

# Printing the area
print("Area of circle is : ",area,unit+"2")

OUTPUT

Enter the circumference of circle : 42
Enter the measure unit of circumference (e.g. in, cm) : cm
Area of circle is : 140.3181818181818 cm2

Explanation

In the code given above, the input() method is used for fetching the circumference from the user. It is then converted into a float value using the float() method. Then the input() method is used for fetching the measurement unit.

The line area = ((circumference  * circumference ) / (4 * (22 / 7) )) determines the area of the circle. If you look at the output you will see that the user has entered 42 as the circumference and m (meters) as the measurement unit. So, the final area of the circle is 140.3181818181818 cm2.

Conclusion

In order to determine the area of the circle, make sure that the radius, circumference and diameter values are correct. Do not forget to convert these value into a float, as they will be entered as strings by the user.