Main Thread
Can we use python built-in Fraction class in order to convert "3.14" to 157/50 ?
No. we would like you to write the relevant code that computes it.
Can you define exactly what should int() method return? Is it supposed round towards zero? What about negatives?
Yes, it should behave as int() behaves on floats.
Should we assume that the input is valid in terms of non-zero denominator, or should we check it?
In general, unless specified otherwise, we assume that the input is valid.
what would you prefer, if you were the user of class Rational?
Also - what do abs(x) and -x return for types such as float, int?
Should I write helper methods inside or outside the class?
Technically - both would work.
Logically, what do you think is more appropriate? Other students are of course welcome to comment as well.
IMO, it depends on the purpose of the method.
If it will be used only in Rational class then it should be within it.
Since that in this HW we are not writing lots of code that will be used by other developers, all methods should be part of the class.
Usually, to follow good design and readable code, all methods that change the state of the Class object, or/and operate on its internal( public or private ) should be inside the class.
Both 'Guest' and Danny are correct.
I would add: if a function is relevant only for a specific method, it may even appear inside that method.
In 1.d. can someone enter "3" or should we assume that it would be "3.0"?
in section 4 - it says that the object to the right of the operator can be both Rational or Int, should I assume that the object to the left has to be Rational?
In 4, the left operand will always be Rational, that's how these methods are defined. ( Left operand - Rational , Right operand - Rational or int). The case of the left operand not being a Rational is handled in section 5.
in 5, there is no point in specifying that the left operand can be a Rational, because if it is, the add function of that Rational will be called and the operation will be valid anyway. Therefore all the 'r…' methods should just handle int.
Please use the gcd code from the lecture. In general, we prefer that the dependency in Python packages that were not taught in class will be as small as possible.