Area of Circle Formule
To calculate the area of a circle, you can use the following formula:
area = π x radius^2
where the radius is the distance from the center of the circle to the edge of the circle.
For example, if the radius of the circle is 5 units, the area would be:
area = π x 5^2 = 25π
The value of π is approximately 3.14159.
You can also use the formula:
area = π x diameter^2 / 4
where the diameter is the distance across the circle through the center of the circle.
For example, if the diameter of the circle is 10 units, the area would be:
area = π x 10^2 / 4 = 25π
Python Program to Calculate Area of Circle using function
Write a program to Calculate Area of Circle in Python 3
Solution 1:
1 2 3 4 5 6 7 8 9 10 11 |
# Python program to find Area of a circle def findArea(r): PI = 3.142 return PI * (r*r); # Driver method num=float(input("Enter r value:")) print("Area is %.6f" % findArea(num)); |
Output:
Solution 2:
Here is a Python function that calculates the area of a circle given the radius:
1 2 3 4 5 6 7 |
import math def calculate_area(radius): area = math.pi * radius**2 return area |
To use the function, you can pass in the radius of the circle as an argument. For example:
1 2 3 4 |
area = calculate_area(5) print(area) |
This would output the area of the circle with a radius of 5 units.
Alternatively, you can define the function to accept the diameter of the circle as an argument and calculate the radius from the diameter before calculating the area:
1 2 3 4 5 6 7 8 |
import math def calculate_area(diameter): radius = diameter / 2 area = math.pi * radius**2 return area |
You can then use the function by passing in the diameter of the circle as an argument. For example:
1 2 3 4 |
area = calculate_area(10) print(area) |
This would output the area of the circle with a diameter of 10 units.