Python program to find the area and circumference of Circle

Python program to find the area and circumference of Circle

Problem Definition:

Write a python program that has a class named Circle. Use a class variable to define the value of a constant PI. Use this class variable to calculate the area and circumference of a circle with the specified radius.

Source code of Python program to find the area and circumference of Circle

class Circle:
    PI = 3.142
    
    def __init__(self, radius):
        self.radius = radius
        
    def area (self):
        return (Circle.PI * self.radius * self.radius)
    
    def circumference(self):
        return (2 * Circle.PI * self.radius)

r = int(input("Enter the radious of circle"))
c1 = Circle(r)
print ("Area of C1 circle is: ", c1.area())
print ("Circumference of C1 Circle is: ", c1.circumference())
print("")
r = int(input("Enter the radious of circle"))
c2 = Circle(r)
print ("Area of C1 circle is: ", c2.area())
print ("Circumference of C1 Circle is: ", c2.circumference())

Output:

Enter the radious of circle5
Area of C1 circle is:  78.55
Circumference of C1 Circle is:  31.419999999999998

Enter the radious of circle6
Area of C1 circle is:  113.112
Circumference of C1 Circle is:  37.704

Video Tutorial

This article discusses, how to write a Python program to find the area and circumference of Circle. Subscribe to our YouTube channel for more videos and like the Facebook page for regular updates.

READ  C++ Interview Question and Answers Part 2

Leave a Comment

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