Exercise 1

Write a subclass called Rcircle of the superclass Circle.

Requirements

  • Must inherit from Circle
  • Must have it's own constructor. The constructor accepts the circle radius supplied by the user as its argument. That is __init__(self, r).
  • The circle radius must be set in the constructor
  • The Rcircle subclass must reimplement the radius function. It does not make sense for Rcircle to inherit the radius method from Circle since an instance of Rcircle doesn't know anything about the coordinates of the circle.
  • Include the __eq__ special method to compare two circles.

Demo your class.

Your Circle class from last time should have looked something like this:


In [1]:
import numpy as np

class Circle:
    
    def __init__(self, x, y):
        self.x = x
        self.y = y
    
    def radius(self):
        self.R = np.sqrt(self.x * self.x + self.y * self.y)
    
    def area(self):
        try:
            self.A = np.pi * self.R* self.R
        except AttributeError:
            r = np.sqrt(self.x * self.x + self.y * self.y)
            self.A = np.pi * r * r
    
    def circum(self):
        try:
            self.C =  2.0 * np.pi * self.R
        except AttributeError:
            r = np.sqrt(self.x * self.x + self.y * self.y)
            self.C = 2.0 * np.pi * r