Question: Write Python Program for the following question an2 + an-12-1 + an-2-3 4. (20 points) Write a class for representing polynomials. A polynomial has the
Write Python Program for the following question


an2" + an-12"-1 + an-2-3 4. (20 points) Write a class for representing polynomials. A polynomial has the following general form + ...Q2 + x2 +211 + ao Any polynomial can be uniquely determined by listing its coefficients (ao, 21, ..., An). Your class must have the following methods evaluate(x): evaluates the polynomial with given input change_coef(n,a): changes the nth coefficient of the polynomial to be a. degree(): returns the degree of the polynomial The constructor should take one list of coefficients. Element 0 of this list represents, coefficient ao; element 1, represents ai, etc. In addition, your class should behave well when: (a) It is used with the print() method (b) Multiply a polynomial by a constant using * operator (C) A polynomial is added to or subtracted from another polynomial using the operators + and - Note: Printing a polynomial is not straight forward. Keep it simple first: print it in the most straightforward and easy way, even if the output does not look very good. You can go back and make it better, if you want, but only after you have finished the rest of this assignment. function with the following line of code. Test your poly1 = Polynomial ((-3, 2]) print (poly1) poly2 = Polynomial ([3, -1, 5]) print (poly2) poly3 = polyi * 3 print (poly3) poly4 = poly2 + poly1 print (poly4) poly5 = poly4 - poly2 print (poly5) Your output should be similar to the following. x + 3 2x 3 5x 2 6x 9 5x^2 + x 2x 3 Process finished with exit code 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
