[CO2] Write a program to create a class Circle. Perform the following operations on it:
a. Define the attribute radius.
b. Define the constructor with one argument containing radius.
c. Define the method named get radius which returns the radius of the circle.
d. Define the method named calc area@ which returns the area of the circle.
Share
Answer:
Certainly! Here's a simple Python program that defines a class `Circle` with the specified operations:
```python
import math
class Circle:
def __init__(self, radius):
self.radius = radius
def get_radius(self):
return self.radius
def calc_area(self):
area = math.pi * self.radius**2
return area
# Example usage:
radius_value = 5
circle_instance = Circle(radius_value)
print(f"Circle Radius: {circle_instance.get_radius()}")
print(f"Circle Area: {circle_instance.calc_area()}")
```
This program defines a `Circle` class with a constructor that initializes the radius attribute. It also has methods to get the radius and calculate the area using the formula πr^2. Finally, an example usage is shown with a circle instance.
please mark me as a brilliant