Python Program to Create a Class and Compute the Area and the Perimeter of the Circle

In this example, we will write a python program to find the area and perimeter of the circle using class and objects. To better understand this example, make sure you have knowledge of the following tutorials:-

Python Program to Create a Class and Compute the Area and the Perimeter of the Circle

The output of the above program is:-

Enter radius of circle: 4
Area of circle: 50.27
Perimeter of circle: 25.13
Program Explanation
Here we have created a class named “Circle” that has an attribute radius. The constructor of the class initiates the attribute using the __init__ function. Two methods “area” and “perimeter” are created to calculate the area of the given circle. We need math library to get the value of PI, so it is imported at the top of the program. Once the class has been defined, we take input from the user as a radius of the circle. An instance of the class “Circle” is created as “obj” and the method is invoked to display the result.
SHARE Python Program to Create a Class and Compute the Area and the Perimeter of the Circle

You may also like...

Leave a Reply

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

Share