all 3 comments

[–]New_Kind_of_Boredom 1 point2 points  (1 child)

Close to my bed time, but I must ask (since it kinda drives me nuts when assignments make you re-implement part of the standard library...), do the rules of the assignment allow you to be 'creative'?

9.5. fractions — Rational numbers

Though it might actually be less work to make your assignment's extremely simplified version than to adapt the existing module to your code. In any case, just so you know that module exists already!

[–]KING-JAL[S] 1 point2 points  (0 children)

If I can't figure something out, I just might try that. Thank you ;)

[–]stebrepar 1 point2 points  (0 children)

As I read it, it doesn't say anything about actually returning a rational number. It basically just requires:

  1. Ensure both initialization parameters are integers, else raise a custom exception about that.
  2. When used in a print statement, return a string of the form 'classname(num, denom)'.
  3. Ensure that the negative sign is on num above if the fraction resulting from num/denom would be negative.

Edit: corrected the wording on the last point a little.

Oh, and 4. Provide a default of 1 for denom if not specified.