Program to calculate the area of circle in Python

by | Jan 14, 2021 | Python Programs

Home » Python » Python Programs » 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.

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

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

Author