Python program to find area of circle
In this post, you will learn about different Python programs to find the area of the circle. As we all know, the area of the circle is the measure of the space or region enclosed inside the circle. In geometry, the area enclosed by a circle of radius r is πr2. Here is the simple formula for calculating the area of the circle.
Area = pi * r2
Algorithm
1. Define a function to calculate area
2. Set PI as constant and initialize to 3.147
3. Use the formula of the Area = πr².
3. Take input of radius from the user
4. Pass radius in the function
5. Print the result
Python program to find area of circle using radius
If we know the radius of a circle, then we can easily calculate the area using the formula: A=πr². Here is the simple Python program to calculate the area of a circle using the radius.
# program to calculate
# area of circle
def area_of_circle(r):
PI = 3.142
return PI * (r*r);
# get user input
radius = float(input("Enter the radius: "))
# print area of circle
print("Area is %.6f" % area_of_circle(radius));
Output of the above code-
Enter the radius: 10
Area is 314.200000
Python program to find area of circle using diameter
Diameter is the distance across the circle passing through the centre. We can also calculate the area of the circle if we know the diameter. Either, we can divide the diameter by 2 and calculate the area using the above process, like this.
# Program to calculate area of circle
def area_of_circle(r):
PI = 3.142
return PI * (r*r);
# get user input
diameter = float(input("Enter the diameter of a circle: "))
radius = diameter / 2
# print area of circle
print("Area is %.6f" % area_of_circle(radius));
Output of the above code-
Enter the diameter of a circle: 53
Area is 2206.469500
Or, we can use the following formula to calculate the area of the circle using diameter.
A=π/4*D²
Here is the program to calculate the area of the circle using the diameter. For this, we first imported the math module and then used the direct formula to calculate the area of the circle.
# Program to calculate area of circle
import math
diameter = float(input("Enter the diameter of a circle: "))
area = (math.pi/4) * (diameter * diameter)
print("Area of circle is %.2f" %area);
Output of the above code -
Enter the diameter of a circle: 23
Area of circle is 415.48
Python program to find area of circle using circumference
The circle's circumference is the distance around the circle. We can easily calculate the area of a circle if we know the circumference using the formula A= C²⁄ 4π, where C is the circumference. The following program demonstrates this.
# Program to calculate area of circle
import math
circumference = float(input("Enter the circumference of a circle: "))
area = (circumference * circumference)/(4 * math.pi)
print("Area of circle is %.2f" %area);
Output of the above code -
Enter the circumference of a circle: 23
Area of circle is 42.10
Related Articles
Python program to multiply two numbers
Multiply all elements in list Python
Find average of n numbers in Python
Sum of n numbers in Python using while loop
Python program to add two numbers
Convert list to dictionary Python
Convert array to list Python
numpy dot product
glob in Python
Python heap implementation
zip function in Python
Remove last element from list Python
Check if list is empty Python
Remove element from list Python
Python split multiple delimiters
Python loop through list
Python iterate list with index
Python add list to list
Python random choice
Python dict inside list
Remove character from string Python
Python raise keyword