Way 1 – Area of Circle Using user-defined pi
In [1]:
radius = float(input("Please Enter Radius : "))
pi = 3.142
area = pi*(radius**2)
print("Area of circle =", area)
Here, we are asking users to enter radius and defined pi as 3.142. Then the area of the circle is calculated using the formula pi*r*r.
Way 2 – Area of Triangle Using Math Module
In [1]:
import math
radius = float(input("Please Enter Radius : "))
pi = 3.142
area = math.pi*pow(radius, 2)
print("Area of circle =", area)
In this approach, we use the math module to calculate the area of the triangle. We are fetching value of pi using math.pi and using pow() function.