Python

Python Program to Calculate Area of Circle using function2 min read

Area of Circle Formule

To calculate the area of a circle, you can use the following formula:

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:

Output:

Solution 2:

Here is a Python function that calculates the area of a circle given the radius:

To use the function, you can pass in the radius of the circle as an argument. For example:

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:

You can then use the function by passing in the diameter of the circle as an argument. For example:

This would output the area of the circle with a diameter of 10 units.