DEV Community

ABUL HASAN A
ABUL HASAN A

Posted on

PROBLEM SOLVING WITH OOPS

1) import math

class Circle:
def init(self, radius_list):
self.radius_list = radius_list

def calculate_area(self):
# Calculate and return the area of each circle in the list
return [math.pi * r ** 2 for r in self.radius_list]

def calculate_circumference(self):
# Calculate and return the circumference of each circle in the list
return [2 * math.pi * r for r in self.radius_list]

def display_circle_info(self):
# Display information about each circle in the list
for i, radius in enumerate(self.radius_list):
area = self.calculate_area()[i]
circumference = self.calculate_circumference()[i]
print(f"Circle {i + 1}:")
print(f"Radius: {radius}")
print(f"Area: {area}")
print(f"Circumference: {circumference}")
print("")

Enter fullscreen mode Exit fullscreen mode




Example usage:

radius_list = [10, 501, 22, 37, 100, 999, 87, 351]
circle_instance = Circle(radius_list)
circle_instance.display_circle_info()
2 ) class Circle:
__pi = 3.141 # Private class variable

def init(self, radius_list):
self.radius_list = radius_list

def calculate_area(self):
# Calculate and return the area of each circle in the list
return [self.__pi * r ** 2 for r in self.radius_list]

def calculate_circumference(self):
# Calculate and return the circumference of each circle in the list
return [2 * self.__pi * r for r in self.radius_list]

def display_circle_info(self):
# Display information about each circle in the list
for i, radius in enumerate(self.radius_list):
area = self.calculate_area()[i]
circumference = self.calculate_circumference()[i]
print(f"Circle {i + 1}:")
print(f"Radius: {radius}")
print(f"Area: {area}")
print(f"Circumference: {circumference}")
print("")

Enter fullscreen mode Exit fullscreen mode




Example usage:

radius_list = [10, 501, 22, 37, 100, 999, 87, 351]
circle_instance = Circle(radius_list)
circle_instance.display_circle_info()
3 )class Circle:
__pi = 3.141 # Private class variable

def init(self, radius_list):
self.radius_list = radius_list

@classmethod
def calculate_area(cls, radius):
# Calculate and return the area of a circle
return cls.__pi * radius ** 2

@classmethod
def calculate_perimeter(cls, radius):
# Calculate and return the perimeter (circumference) of a circle
return 2 * cls.__pi * radius

def display_circle_info(self):
# Display information about each circle in the list
for i, radius in enumerate(self.radius_list):
area = self.calculate_area(radius)
perimeter = self.calculate_perimeter(radius)
print(f"Circle {i + 1}:")
print(f"Radius: {radius}")
print(f"Area: {area}")
print(f"Perimeter: {perimeter}")
print("")

Enter fullscreen mode Exit fullscreen mode




Example usage:

radius_list = [10, 501, 22, 37, 100, 999, 87, 351]
Circle.display_circle_info(radius_list)

Top comments (0)