r
, representing the radius of the circle.3
Sample Output:28.27
input()
function to get the radius of the circle from the user.area = π * r^2
to calculate the area.math
Modulemath
module provides a built-in constant math.pi
for the value of π (pi), which makes calculations precise and straightforward.import math
# Program to calculate the area of a circle
radius = float(input("Enter the radius of the circle: "))
area = math.pi * radius ** 2
print("%.2f" % area)
Sample Input:6
Sample Output:113.10
# Program to calculate the area of a circle
PI = 3.14
radius = float(input("Enter the radius of the circle: "))
area = PI * radius ** 2
print("%.2f" % area)
Sample Input:8
Sample Output:200.96
import math
def area_of_circle(radius):
return math.pi * radius ** 2
# Input from the user
radius = float(input("Enter the radius of the circle: "))
print("%.2f" % area_of_circle(radius))
Sample Input:3
Sample Output:28.27
math
module is the most precise and preferred approach for real-world applications. For quick and simple tasks, using a hardcoded value of π or a function can also be effective.For more tutorials like this, Click Here to Know more our program!