def __add__(self, other):
if type(other) in (int, long):
return rational(self.num + other * self.den, self.den)
return rational(self.num * other.den + other.num * self.den,
self.den * other.den)
If you're using Python 2.2 (or later), you'd be better writing the "type(other) in (int, long)" as "isinstance(other, (int, long))".
Assuming an operand that isn't an integer or a long is a rational is going to lead to some wierd tracebacks, I'd have thought.
Finally:
def __init__(self, num, den=1):
would seem to be a win, from here.
You didn't say you wanted criticism, but you got it anyway :)
