The area of a circle can be calculated using the formula: Area = π * r^2, where r is the radius of the circle and π (pi) is a mathematical constant approximately equal to 3.14159.
import math
def calculate_circle_area(radius):
return math.pi * radius ** 2
# Taking input from the user for the radius
radius = float(input("Enter the radius of the circle: "))
area = calculate_circle_area(radius)
print("Area of the circle with radius", radius, "is:", area)
Enter the radius of the circle: 5
Area of the circle with radius 5 is: 78.53981633974483
Enter the radius of the circle: 10
Area of the circle with radius 10 is: 314.1592653589793
The function calculate_circle_area(radius)
takes the radius of the circle as input and returns its area using the formula π * r^2, where π is the mathematical constant pi and r is the radius.
The example usage section demonstrates how to take input from the user for the radius, calculate the area of the circle, and print the result.