The Circle Object

The Circle Object

Define a class called ‘Circle’ with private data members: ‘radius’  and ‘color‘ where ‘radius’  is a float value and   ‘color‘  is a string value.  This class should contain a parameterized constructor with 2 arguments to initialize these data members.  The arguments should be radius and color.  The ‘Circle’ class also contain the following methods:

calculate_area()  –  This function is used to calculate and return the area of the circle.  The formula to calculate area of a circle is :3.14 *radius*radius.

calculate_perimeter() –  This function is used to calculate and return the perimeter of the circle.  The formula to calculate perimeter is : 2*3.14*radius.

Get the values for radius and color from the user and store it into the variables with the names  ‘my_radius‘  and ‘my_color ‘ respectively.  Both variables should be in the global scope.

Create a method ‘check_validity(my_radius,my_color)’ in the global scope (should not be a class member function) for checking the validity of the radius, the user has entered.  This method should take 2 parameters; radius and the color entered by the user.  If the radius is ‘0’ or a negative value, then this function shouldreturn the Boolean value ‘False’ else it should create a circle object using 2 arguments parameterized constructor.

Store the object returned from the function ‘check_validity(my_radius,my_color)‘ (boolean value ‘False‘ or the circle object) into a reference variable named ‘circle_obj‘ which should be in the global scope.

If the returned value is a ‘Circle’ class object,  then perform 2 operations:
1.    Calculate the area of the circle by invoking the ‘Circle‘ class’s ‘calculate_area()‘ method using the object ‘circle_obj’ and display it.
2.    Calculate the perimeter of the circle by invoking the ‘Circle‘ class’s ‘calculate_perimeter()’ method using the object ‘circle_obj’ and display it.

If the ‘check_validity(my_radius,my_color)’ returns the Boolean value ‘False‘ then display the message “Invalid Radius” and stop the program.

Note:

• The values for the variables my_radius and my_color should be user inputs
• Strictly follow the naming conventions for variables and functions as specified in the problem description.

Sample input 1:
Enter the radius of the circle: 6
Enter the color of the circle: Red

Sample Output 1:
Area is: 113.04
Perimeter is: 37.68

Sample input 2:
Enter the radius of the circle:-8

Sample output 2:

Code :-

```class Circle:
self.__color=color

def get_color(self):
return self.__color
def set_color(self,color):
self.__color=color

def calculate_area(self):
def calculate_perimeter(self):

my_color=input("Enter the color of the circle: ")