Python Program to Find the Area and Perimeter of a Circle using Class

Object-oriented programming (OOP) allows us to create classes that encapsulate data and methods. This program demonstrates how to create a Python program that calculates the area and perimeter of a circle using a class.

Problem Statement

Write a Python program that defines a class for a circle, calculates its area and perimeter, and provides methods to access these values.

Python Program to Find the Area and Perimeter of a Circle using Class

import math

class Circle:
    def __init__(self, radius):
        self.radius = radius

    def calculate_area(self):
        return math.pi * self.radius ** 2

    def calculate_perimeter(self):
        return 2 * math.pi * self.radius

# Input
radius = float(input("Enter the radius of the circle: "))

# Creating a Circle object
circle = Circle(radius)

# Calculating area and perimeter
area = circle.calculate_area()
perimeter = circle.calculate_perimeter()

# Output
print("Circle with radius", radius)
print("Area:", area)
print("Perimeter:", perimeter)
Python Program to Find the Area and Perimeter of a Circle using Class

Leave A Reply

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

You May Also Like

In this python tutorial, you will learn how to Display Prime Numbers Between Two Intervals using the if and else...
In this python tutorial, you will learn how to Calculate Standard Deviation with built in functions of the python programming...
In this Python program, we will convert temperature values from Celsius to Fahrenheit. The Celsius and Fahrenheit scales are two...