Example #1
0
 def __truediv__(self, other):
     if (type(other) == komplex):
         divisor = other.r * other.r - other.i * -other.i
         dividend = komplex(self.r, 0) * komplex(other.r, -other.i)
         return (komplex(dividend.r / divisor, dividend.i / divisor))
     elif (type(other) == rational):
         return (rational(self.r / other.r))
     elif (type(other) in [str, float, int]):
         try:
             return (rational(self.r / float(other)))
         except:
             print("Warning: '", other,
                   "' value couldn't be converted into float")
             return (self)
Example #2
0
 def __add__(self, other):
     if (type(other) == komplex):
         return (komplex(self.r + other.r, 0 + other.i))
     elif (type(other) in [rational]):
         return (rational(self.r + other.r))
     elif (type(other) in [str, float, int]):
         try:
             return (rational(self.r + float(other)))
         except:
             print("Warning: '", other,
                   "' value couldn't be converted into float")
             return (self)