title: How can I multiply two polynomials in Python using a loop and by calling another function?
body: <p>I've been working at this problem for a couple hours now, but I don't know where to start or do anything. I understand the math/logic behind it, but I don't know to put it into code very well.</p>
  
  <p>This is the problem:</p>
  
  <ol>
  <li>Write and test a function <em>multiply(self, other)</em> that returns the product of two polynomials. Use one loop(for or while); within it call *multiply_by_one_term* from a previous question.</li>
  </ol>
  
  <p>This is what I have set up in the beginning, I can't recall what it's called:</p>
  
  <pre><code>class Polynomial:
      def __init__(self, coeffs=[0]):
          self.coeffs = coeffs
  </code></pre>
  
  <p>This is the test I have made:</p>
  
  <pre><code>def multiply(self, other):
      """
        &gt;&gt;&gt; p1 = Polynomial([1, 2])
        &gt;&gt;&gt; p2 = Polynomial([3, 4])
        &gt;&gt;&gt; p1.multiply(p2).coeffs
        [3, 10, 8]
      """
  </code></pre>
  
  <p>This is the function I need to call:</p>
  
  <pre><code>def multiply_by_one_term(self, a, exp):
      """       
        &gt;&gt;&gt; p = Polynomial([2, 1, 3])
        &gt;&gt;&gt; p.multiply_by_one_term(3, 2).coeffs
        [6, 3, 9, 0, 0]
        &gt;&gt;&gt; p = Polynomial([2, 1, 3])
        &gt;&gt;&gt; p.multiply_by_one_term(3, 0).coeffs
        [6, 3, 9]
      """
  
      return Polynomial([a*i for i in self.coeffs] + [0]*exp)
  </code></pre>
  
  <p>I would really appreciate it if someone could help me with this. I'm still a noob when it comes to programming and I don't know it very well.</p>