Python Program to find area of circle
Program
import math;
radius = int(input("Enter the radius of circle:\t"))
area = math.pi * radius * radius
print("The area of circle is:\t{0}".format(area))
This program calculates the area of a circle using the formula:
[
\text{Area} = \pi \times \text{radius}^2
]
where ( \pi ) (Pi) is approximately 3.14159.
import math;
- Imports the
mathmodule, which provides mathematical functions including the constantmath.pi(which represents the value of π).
radius = int(input("Enter the radius of circle:\t"))
- The user is prompted to enter the radius of the circle.
input()function reads the input as a string.int()converts the input string into an integer.
area = math.pi * radius * radius
- The formula for the area of a circle is used:
[
\text{Area} = \pi \times \text{radius}^2 ] math.piprovides the value of π (3.141592653589793).- The calculated area is stored in the variable
area.
print("The area of circle is:\t{0}".format(area))
- The
print()function displays the computed area using string formatting.
Key Takeaways:
- Uses
math.pito get an accurate value of π. - Uses the formula ( \pi \times \text{radius}^2 ) to compute the area.
- Uses
input()to take user input andformat()for formatted output.
Output
Enter the radius of circle: 6
The area of circle is: 113.097335529