Calculating the area of circle using Python

How to find area of circle

Area of circle is the number of square units inside the circle , can be calculated using the radius and diameter.The formula for evaluating the area of circle is

  • Area of circle using radius=   Pi*r*r    ( r is the radius of circle)
  • Area of circle using diameter=  1/4*Pi*d*d   ( d is the diameter of circle)

Pi is a Greek letter and the value of Pi is equal to 3.14159265359. In the program we will be initiating Pi as global variable or we can simply import from math module present in python.Syntax for importing pi from math module : from math import pi

calculating area of circle using python

Algorithm

1.Input radius/diameter

2.Calculate area of circle using formula

             area= pi*r*r(if radius is given as input)

             area=(pi*d*d)/4 (if diameter is given as input)

3.Print area

 

PYTHON CODE

from math import pi
r=float(input(“Enter radius of circle :”))
area=pi*r*r
print(“The area of circle is”,end=” “)
print(area)
from math import pi
d=float(input(“Enter diameter of circle :”))
area=(pi*d*d)/4
print(“The area of circle is”,end=“”)
print(area)