Python programming - Practice questions
1) Create a Complex class to represent a complex number of the form x + iy, with data attributes x (real
part) and y (imaginary part). Provide member functions to:
a) Read and display complex numbers.
b) Add two complex numbers.
c) Subtract a complex number from another.
d) Multiply two complex numbers.
e) Divide a complex number by another complex number.
Note:
• Do not use the inbuilt complex number handling method(s).
• Employ the concept of operator overloading using __add__, __sub__, __mul__, and __trudiv__
methods for addition, subtraction, multiplication and division respectively (items (b) to (e) above).
• Implement the above class in a program.
2) Create a Triangle class to represent triangles with three data attributes a, b and c representing its
sides. Provide member functions to:
a) Accept the sides of the triangle.
b) Display the sides of the triangle.
c) Find whether the sides represent an equilateral triangle.
d) Find whether the sides represent an isosceles triangle.
e) Find whether the sides represent a right-angled triangle.
Note: Implement the above class in a program.