# Python Program to Find Area of Circle

Area of Circle in Python | Here, we will discuss all possible methods to write a python program to calculate the area of the circle. The radius of the circle will be given and the python program will calculate the area of the circle using various methods.

Area of Circle

Where,
ℼ = pi = 3.14

Mathematically,

Input : r = 5
Area of circle = 3.14 x 5 x 5 = 78.5

Now let’s see how we can implement the area of circle calculator in Python.

## Python Program for Area of Circle

Program description:- Write a Python program to find the area of the circle.

This is the simplest and easiest way to calculate the area of the circle in python. We will take the radius when declaring the variable, the value of the area will be calculated and stored in the variable, and finally, it will be displayed on the screen.

# python program to find area of circle

# take inputs
r = 10

# calculate area of circle
area = 3.14 * r * r

# display result
print('Area of circle = ',area)

Output:-

Area of circle = 314.0

In this program, we have hardcoded the value of radius in the source code.

r = 10

Now, calculate the area of the circle using formula.

area = 3.14 * r * r

Then, the value of the area is displayed using the print() function.

print('Area of circle = ',area)

Find the area of circle where the radius is provided by the user

In the previous program, the radius is hardcoded in the program but in this program, the radius will be provided by the user.

# python program to find area of circle

# store input
r = float(input('Enter the radius of the circle: '))

# calculate area of circle
area = 3.14 * r * r

# display result
print('Area of circle = %.2f ' %area)

Output:-

Enter the radius of the circle: 3
Area of circle = 28.26

Enter the radius of the circle: 7.5
Area of circle = 176.62

In this program, Inputs (the radius of the circle) will be provided by the user. Inputs are scanned using the input() function. input() method reads user input as a string. So, we need to convert it to float first and store it in variable r.

r = float(input('Enter the radius of the circle: '))

Then, calculate the area of the circle using the formula, and the value of the area is displayed using the print() function.

## Find Area of Circle using Math File

We can without providing PI value, directly using the math library for the imported value of PI and calculate the area of the circle. This supports us to use all the mathematical functions in Python programming. The main drawback of this method is that we need to create a separate variable to hold this value.

# python program to find area of circle using math file

import math   # math file

# store input
r = float(input('Enter the radius of the circle: '))

# calculate area of circle
area = math.pi * r * r

# display result
print('Area of circle = %.2f ' %area)

Output:-

Enter the radius of the circle: 1.5
Area of circle = 7.07

## Using Functions

This is a different method to calculate the area of the circle program in python. We can also take the help of function. A function is a block of code that performs a specific task.

# python program to find area of circle using functions

import math     # math file

def area_of_circle(r):      #user-defined function
area = math.pi * r * r     # calculate area of circle
return area            #return value

# store input
r = float(input('Enter the radius of the circle: '))

# display result
print('Area of circle = %.2f ' %area_of_circle(r))

Output:-

Enter the radius of the circle: 3.28
Area of circle = 33.80

In this program, we will be the first defined function. Radius is scanned using the input() function and stored in variables r. Then call the function and print the area of the circle.

Also See:- Compound Interest Program in Python

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!