Question: ************************* PYTHON ******************* class RationalNumber : Reference: https://anandology.com/python-practice-book/object_oriented_programming.html Rational Numbers with support for arthmetic operations. >>> a = RationalNumber(1, 2) >>> b = RationalNumber(1,

************************* PYTHON *******************

************************* PYTHON ******************* class RationalNumber: """ Reference: https://anandology.com/python-practice-book/object_oriented_programming.html Rational Numbers with support

class RationalNumber: """ Reference: https://anandology.com/python-practice-book/object_oriented_programming.html Rational Numbers with support for arthmetic operations. >>> a = RationalNumber(1, 2) >>> b = RationalNumber(1, 3) >>> a + b 5/6 >>> a - b 1/6 >>> a * b 1/6 >>> a/b 3/2 """ def __init__(self, numerator, denominator=1): """  """ self.n = numerator self.d = denominator def __add__(self, other): 
 """  """ if not isinstance(other, RationalNumber):
 other = RationalNumber(other) n = self.n * other.d + self.d * other.n d = self.d * other.d return RationalNumber(n, d) def __sub__(self, other): """ 
  """
 if not isinstance(other, RationalNumber): other = RationalNumber(other) n1, d1 = self.n, self.d n2, d2 = other.n, other.d return RationalNumber(n1*d2 - n2*d1, d1*d2) def __mul__(self, other): 
 """  """
 if not isinstance(other, RationalNumber): other = RationalNumber(other) n1, d1 = self.n, self.d n2, d2 = other.n, other.d return RationalNumber(n1*n2, d1*d2) def __div__(self, other): 
 """  """
 if not isinstance(other, RationalNumber): other = RationalNumber(other) n1, d1 = self.n, self.d n2, d2 = other.n, other.d return RationalNumber(n1*d2, d1*n2) def __str__(self): 
 """  """
 return "%s/%s" % (self.n, self.d) __repr__ = __str__

Now do the following Start with the program below Fill in the missing method docstrings, one for each instance method Modify the following program so that you can support addition, subtraction, multiplication, and division with scalar (int or float) values. For examplea -RationalNumber (1, 4 ) print( b) should print out the value 1/8 For now, assume that scalar values will occur always on the right-hand-side of the arithmetic operator in question Define your own exception class named unexpectedargumentType, which should subclass from TypeError and should be raised from your arithmetic operator implementations when the input parameter is of an unexpected type. For example, if the calling context provides (RationalNumber, RationalNumber) or (RationaINumber, int), or (Rationa1Number, float), the operation should proceed. Otherwise, an UnexpectedArgumentType exception should be raised from your code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!