I wanna create a function to generate a polynomial with corresponding coefficients.
class Polynomial:
def __init__(self, *coefficients):
self.coefficients = coefficients
def __len__(self):
return len(self.coefficients)
def __repr__(self):
equation = ""
for i in range(len(self)):
if i == 0:
equation += "(" + str(self.coefficients[i]) + "x^" + str(i)
else:
equation += "+" + str(self.coefficients[i]) + "x^" + str(i)
return equation + ")"
def __lt__(self, other):
return self.coefficients < other.coefficients
def __ge__(self, other):
return self.coefficients >= other.coefficients
a = Polynomial(1,2,3)
print(a)
I expected '(1x^0+2x^1+3x^2)' to be printed, but It was just (1x^0). What would be the problem in my code? thank you in advance.