Home » Python » Python programs

# 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?**

Submitted by Shivang Yadav, on April 03, 2021

**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: **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.

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions