Python program to find the area and perimeter of a circle

Here, we are going to learn how to calculate the area and perimeter of a circle in Python? By Shivang Yadav Last updated : April 09, 2023

Area of Circle

It is the area occupied by the circle. Given by the formula,

Area = π*R*R

Value of π = 3.14, R is the radius of a circle.

Perimeter of Circle

Perimeter of Circle: Also known as the circumference. It is given by the formula,

Perimeter = 2*π*R

Value of π = 3.14, R is the radius of a circle.

We will use these formulas for finding the area and perimeter of the circle with a given radius. The value of π can either be used directly or can be extracted using the pi value in the math library in Python.

Program to find area and perimeter of a circle

# Python program to find the 
# area and perimeter of circle in python

# Initialising the value of PI
PI = 3.14
# Getting input from user
R = float(input("Enter radius of the circle: "))

# Finding the area and perimeter of the circle
area = (PI*R*R)
perimeter = (2*PI*R)

# Printing the area and perimeter of the circle 
print("The area of circle is", area)
print("The perimeter of circle is", perimeter)

Output

RUN 1:
Enter radius of the circle: 1.2
The area of circle is 4.521599999999999
The perimeter of circle is 7.536

RUN 2:
Enter radius of the circle: 35.63
The area of circle is 3986.2202660000007
The perimeter of circle is 223.7564

Explanation

In the above code, we have initialized the value of PI with 3.14. Then asked the user for an input for the value of R. Using the formulas, we calculated the value of area and perimeter and printed it.

We can also get the value of PI using the built-in value in Python's math library.

Syntax:

math.pi

Program to find area and perimeter of a circle using math library

# Python program to find the 
# area and perimeter of a circle in python

from math import pi

# Getting input from user
R = float(input("Enter radius of the circle: "))

# Finding the area and perimeter of the circle
area = (pi*R*R)
perimeter = (2*pi*R)

# Printing the area and perimeter of the circle 
print("The area of circle is ", "%.2f" %area)
print("The perimeter of circle is", "%.2f" %perimeter)

Output

RUN 1:
Enter radius of the circle: 1.2
The area of circle is  4.52
The perimeter of circle is 7.54

RUN 2:
Enter radius of the circle: 35.63
The area of circle is  3988.24
The perimeter of circle is 223.87

Explanation

In the above code, we have imported the value of pi from the math library for use in the program. Then asked the user for an input for the value of R. Using the formulas, we calculated the value of area and perimeter and printed it.

To understand the above example, you should have the knowledge of the following Python topics:

Python Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.