Table of Contents
Introduction
In this article, we are going to understand the python code to calculate the area of circle. To calculate the area of circle we should know the radius or diameter value of circle. Area is calculated by the given formula:
Area of circle = ∏*r2 Where, ∏ = pi having constant value = 3.14 r = radius of circle
Program
def area_circle(r): pi = 3.14 r = float(r) area = pi*r*r print("Area of circle of radius {0} is {1}".format(r,area)) r = input("Please enter the radius of circle ") area_circle(r)
Output:
Explanation
In the above python program, we have created a function area_circle() to calculate the area based on the input radius of circle. The radius is casted into float as the user might enter the float value and also as the pi has constant value 3.14, the arithmetic calculation of integer and float will give error.
0 Comments