7.10 More polynomial magic
Now that we’ve laid the groundwork for polynomials, it’s time to implement operations like addition, subtraction, and multiplication. Since we are restricting ourselves to integer coefficients, we do not implement division.
7.10.1 A better __str__
We’ll start to see more than one term, and we need a more robust implementation of __str__.
def __str__(self):
"""Creates a human-readable string representation.
This returns forms that look like 2x**6 + x**3 - 1.
Returns
-------
str
Mathematical human-readable form of the polynomial.
"""
if not self.__terms:
return '0'
def format_term(coefficient, exponent):
"""Format a single term in the polynomial.
This function formats a term and handles the special
cases when the coefficient is +/- 1 or the exponent is
0...