Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Polynomial:
- def __init__(self, *coeffs):
- self.coeffs = coeffs
- def __repr__(self):
- return 'Polynomial{}'.format(self.coeffs)
- # | this bit here
- def __add__(self, other): #v this bit here
- return Polynomial(*(x + y for x, y in zip_longest(self.coeffs, other.coeffs))) #This is the line specifically
- p1 = Polynomial(1, 2, 3) # x^2 + 2x + 3
- p2 = Polynomial(3, 4, 3) # 3x^2 + 4x + 3
- p3 = p1+p2
- print(p3) #Result was as expected, "Polynomial(4, 6, 6)"
Add Comment
Please, Sign In to add comment