Coding Assignments ( Python Object Oriented Programming )- Problems and Solutions
This article contains coding exercises related to python object oriented programming
NOTE : The solutions are given at the last of this article. But try to write your code before taking the help of the solutions.
Problem 1 (Rectangle)
Write a Python class named Rectangle constructed by a length and a width. The Rectangle class has the following methods.
a ) constructor method
b) area(self) - returns the area of the rectangle
c) perimeter(self) - return the circumference of the rectangle
d) special method - that compares the area of 2 rectangles
Problem 2 (Circle)
Define a class named Circle which can be constructed by a radius. The Circle class has following methods
a) constructor method
b) area(self) - returns the area of the circle
c) circumference(self) - returns the circumference of the circle
Problem 3 (Triangle)
Define a Triangle class for triangle objects that have 3 properties (sides of the triangle). Write the following methods for Triangle class
1) Constructor method
2) calculate_perimeter(self) - it returns perimeter of the triangle
3) calculate_area(self) - it returns the area of the triangle
4) check_right_trinagle(self): - it returns True if the triangle is right-angle triangle otherwise returns False.
5) Write magic methods to compare the areas of two triangles.
Solutions
1) Problem 1 - python_oops_01 - Replit
2) Problem 2 - python_oops_02 - Replit
3) Problem 3 - python_oops_03 - Replit