Guest User

Untitled

a guest
Jun 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. class Polynomial:
  2. def __init__(self, *coeffs):
  3. self.coeffs = coeffs
  4.  
  5. def __repr__(self):
  6. return 'Polynomial{}'.format(self.coeffs)
  7. # | this bit here
  8. def __add__(self, other): #v this bit here
  9. return Polynomial(*(x + y for x, y in zip_longest(self.coeffs, other.coeffs))) #This is the line specifically
  10.  
  11. p1 = Polynomial(1, 2, 3) # x^2 + 2x + 3
  12. p2 = Polynomial(3, 4, 3) # 3x^2 + 4x + 3
  13. p3 = p1+p2
  14. print(p3) #Result was as expected, "Polynomial(4, 6, 6)"
Add Comment
Please, Sign In to add comment