Python – Program to Find Area of a Circle

Python – Program to Find Area of a Circle

In this post, we will write a program for how to calculate the area of a circle in python.
First, let’s see What is the Area of Circle?
The area enclosed by a circle of radius r in 2-dimensional plane.
Formula:

Area of circle: A = pi * r * r Or pi * r 2
Where,
r = Radius of circle 
pi = pi is geek letter which is a constant whose approximate value is 3.14159...

Examples:

Input: Radius = 7
Output: The area of the circle is 154.0

Input: Radius = 2
Output: The area of the circle is 12.56

Let’s see the program for this:
Code Version 1: Create a user-defined function that will calculate and print the area of a circle.

# define a function for
# finding area of a circle 
def area(r):
        
        # constant value of PI
	PI = 22/7
	
	# printing the radius
	print("Radius =", r)
	
	# calculating the area
	area = PI * (r * r)
	
	# printing the area
	print("The area of the circle is", area)

# main code
if __name__ == "__main__" :

    # input radius
    radius = 7

    # function calling
    area(radius)	

Output:

Radius = 7
The area of the circle is 154.0

Code Version 2: Create a user-defined function that will calculate and print the area of a circle. In this code version, we are using pi constant value which is directly taken from the math library.

# including pi constant
# from the math library
# into this program
from math import pi

# defina a function for
# finding area of circle 
def area(r):

	
	# printing the radius
	print("Radius =", r)
	
	# calculating the area
	area =  pi * (r * r)
	
	# printing the area
	print("The area of the circle is", area)

# main code
if __name__ == "__main__" :

    # input radius
    radius = 7

    # function calling
    area(radius)

Output:

Radius = 7
The area of the circle is 153.93804002589985

Leave a Reply

Your email address will not be published.

📢 Need further clarification or have any questions? Let's connect!

Connect 1:1 With Me: Schedule Call


If you have any doubts or would like to discuss anything related to this blog, feel free to reach out to me. I'm here to help! You can schedule a call by clicking on the above given link.
I'm looking forward to hearing from you and assisting you with any inquiries you may have. Your understanding and engagement are important to me!

This will close in 20 seconds