Due Tuesday 8-Oct, at 9:00pm
hw6
hw6.py
(We are not providing a starter file this week.)hw6.py
and build the functions as described below.hw6.py
to Gradescope. You may submit up to 10 times, but only your last submission counts.Do not use sets, dictionaries, try/except, classes, or recursion this week. The autograder (or a manual CA review later) will reject your submission entirely if you do.
Like in the previous assignment, we will be grading your code based on whether it follows the 15-112 style guide. We may deduct up to 10 points from your overall grade for style errors. We highly recommend that you try to write clean code with good style all along, rather than fixing your style issues at the end. Good style helps you code faster and with fewer bugs. It is totally worth it. In any case, style grading already started, so please use good style from now on!
There is no skeleton file provided this week, meaning that we also are not providing testcases. You should write testcases for each function. (You can find some nice ways to test in the write-up below, but you will need to translate those to actual testcases.)
We can represent a polynomial as a list of its
coefficients. For example, we will represent the polynomial
2x3 + 3x2 + 4 with the list
[2, 3, 0, 4]
.
With this in mind, write the function
multiplyPolynomials(p1, p2)
, which takes two lists
representing polynomials as described above, and returns the list
representing the polynomial that is the product of p1
and p2
.
For example, multiplyPolynomials([2, 3, 0, 4], [1, 5])
represents the problem (2x3 + 3x2 + 4)(x + 5).
This equals
2x4 + 13x3 + 15x2 + 4x + 20. So the
function would return [2, 13, 15, 4, 20]
.
How did we find that answer? To multiply two polynomials
p1
and p2
, you do this:
p1
by each term in
p2
, thenx
.firstNAcceptedValues(n, rules)
from CS Academy.
You must solve the problem directly on the website, doing all of your testing there. Do not write the solution in Thonny (or a different IDE) and copy/paste it into the website.