Program to calculate the area of circle in Python

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

area 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:

Program to calculate the area of circle in Python

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.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.