Python Assignment Help: Rational Class Homework Assignment

Updated: Aug 14, 2019

Chapter 12, page 610, problem 2.

“Augment the Rational number class to include multiplication and division. Include the ability to accommodate operands of type int.”

In sections 12.1 – 12.4 the authors developed the structure of the Rational class. They implemented most of the addition and subtraction operators as well as the equality operator. Further, they demonstrated how to write the __radd__ method for adding an integer to a rational number, rather than adding a rational to an integer.


 In class, we showed how to use the equality operator and assert to test addition and

subtraction. You may start with the code which we developed in class, but note that not everything was

implemented for addition and subtraction. You must implement everything for addition, subtraction,

multiplication, and division to finish the Rational class.


Notes (specific details!):

1. Except for testing __init__, __str__, __repr__, and __eq__, for this project you must use

assert for all of your tests.

2. Instead of __div__, you must use __truediv__ to implement the division operator.

3. All operations must be able to handle an integer as an operand as well, from both the left and the

right. Examples: r1 + 3, 5 + r2, or r2 /4 or 4/r5.

Contact Us

Tel: (+91) 0120  4118730  

Time :   10 : 00  AM -  08 : 00 PM IST 

Registered address: G-69, Sector 63, 

 Noida - 201301, India

We Provide Services Across The different countries

USA    Australia   Canada   UK    UAE    Singapore   New Zealand    Malasia   India   Ireland   Germany

CodersArts is a Product by Sofstack Technology Solutions Pvt. Ltd.

  • CodersArts | Linkedin
  • Instagram