Hey all, I'm trying to write a Polynomial Class but I'm having some trouble. I'm having the coefficients and exponents stored in a dictionary, like so...
class Polynomial:
def __init__(self, *termpairs):
self.termdict = dict(termpairs)
print (self.termdict)
if __name__ == '__main__':
d1 = Polynomial((2,3), (4,5), (8,9))
print (d1)
This will give me...
{8: 9, 2: 3, 4: 5}
Now I want to also have an __str__ method, however, I'm not quite sure how to represent this as a string. Polynomial((2,3), (4,5), (8,9)) as a string should look like:
2x^3 + 4x^5 + 8x^9
Anyone have any tips?