title: How to calculate sum of two polynomials?
body: <p>For instance 3x^4 - 17x^2 - 3x + 5.  Each term of the polynomial can be represented as a pair of integers (coefficient,exponent).  The polynomial itself is then a list of such pairs like<br>
  <code>[(3,4), (-17,2), (-3,1), (5,0)]</code> for the polynomial as shown.</p>
  
  <p>Zero polynomial, 0, is represented as the empty list <code>[]</code>, since it has no terms with nonzero coefficients.</p>
  
  <p>I want to write two functions to add and multiply two input polynomials with the same representation of tuple (coefficient, exponent):</p>
  
  <ol>
  <li><code>addpoly(p1, p2)</code></li>
  <li><code>multpoly(p1, p2)</code></li>
  </ol>
  
  <p>Test Cases:</p>
  
  <ul>
  <li><p><code>addpoly([(4,3),(3,0)], [(-4,3),(2,1)])</code> <br>
  should give <code>[(2, 1),(3, 0)]</code></p></li>
  <li><p><code>addpoly([(2,1)],[(-2,1)])</code> <br>
  should give <code>[]</code></p></li>
  <li><p><code>multpoly([(1,1),(-1,0)], [(1,2),(1,1),(1,0)])</code> <br>
  should give <code>[(1, 3),(-1, 0)]</code></p></li>
  </ul>
  
  <p>Here is something that I started with but got completely struck!</p>
  
  <pre><code>def addpoly(p1, p2):
      (coeff1, exp1) = p1
      (coeff2, exp2) = p2
      if exp1 == exp2:
          coeff3 = coeff1 + coeff2
  </code></pre>