top of page

Python Assignment Help: Rational Class Homework Assignment

Updated: Mar 19, 2021

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.


IMPORTANT

 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.


 IMPORTANT

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.

Comments


bottom of page