Answer to Question #305397 in Python for NST

Question #305397

Add two polynomials

Given two polynomials A and B, write a program that adds the give

two polynomials A and B.




Output


Print the addition of polynomials A and B.


If the term with highest degree is negative, the term should be represented as -Cix^ ^ Pi .


For the term where power is 1 represent it as C1x instead of Cl*^ ^ 1 .


If the degree of polynomial is zero and the constant term is also ero, then just print 0 to represent the polynomial. For Lerm Cix^ ^ p i if the coefficient of the term Ci is 1, simply print x ^ P * i


instead of 7x p1


Explanation


If M = 4 and for polynomial A

For power 0, co-efficient is 5

For power 1, co-efficient is 0

For power 2, co-efficient is 10

For power 3, co-efficient is 6.


If N = 3 and for polynomial B

For power 0, co-efficient is 1

For power 1, co-efficient is 2

For power 2, co-efficient is 4.


And if result is zero print 0.


And if result has 1x solution it only x.





1
Expert's answer
2022-03-03T09:59:46-0500
from numpy import poly1d
def disp_poly(i):
    list1 = []
    for i in range(i):
        n = input('Enter coefficients')
        list1.append(int(n))
    poly_input = poly1d(list1)
    return poly_input
        
print(disp_poly(4) + disp_poly(3))   
Enter coefficients6
Enter coefficients10
Enter coefficients0
Enter coefficients5
Enter coefficients4
Enter coefficients2
Enter coefficients1
   3      2
6 x + 14 x + 2 x + 6

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS