Add two Rats, or a Rat and a number.
(self, other)
| 79 | raise ValueError("can't convert %s to int" % repr(self)) |
| 80 | |
| 81 | def __add__(self, other): |
| 82 | """Add two Rats, or a Rat and a number.""" |
| 83 | if isint(other): |
| 84 | other = Rat(other) |
| 85 | if isRat(other): |
| 86 | return Rat(self.__num*other.__den + other.__num*self.__den, |
| 87 | self.__den*other.__den) |
| 88 | if isnum(other): |
| 89 | return float(self) + other |
| 90 | return NotImplemented |
| 91 | |
| 92 | __radd__ = __add__ |
| 93 |