Question: Please help me fix my code in python!: def print _ poly ( polynomial ) : terms = [ ] degree = len ( polynomial

Please help me fix my code in python!:
def print_poly(polynomial):
terms =[]
degree = len(polynomial)-1
for exp in range(degree,-1,-1):
coef = polynomial[exp]
if coef !=0:
sign ='+' if coef >0 and len(terms)>0 else '-' if coef <0 else '' # Determine sign
coefficient = abs(coef)
if coefficient.is_integer():
coefficient = int(coefficient)
term = f"{sign}{'' if coef !=0 and len(terms)>0 else ''}{coefficient}" if exp ==0 else f"{sign}{'' if coef !=0 and len(terms)>0 else ''}{coefficient}x" if exp ==1 else f"{sign}{'' if coef !=0 and len(terms)>0 else ''}{coefficient}x^{exp}"
terms.append(term)
printed_polynomial =''.join(terms)
print(printed_polynomial)
I need it to simplify 1x to just be x.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!