Problem Statement:
We need to take an integer(n) as input, then next to n lines, there will be two separated integers representing Pi and Ci of a polynomial. We need to represent those Pi and Ci in polynomial form.
For example,
Input
Enter number of terms in polynomial: 5
1 2
2 3
3 4
0 9
7 6
Output
6x^7 + 4x^3 + 3x^2 + 2x^1 + 9x^0
Code for Polynomial in Python:
n = int(input('Enter number of terms in polynomial: ')) Pi = [] Ci = [] for i in range(n): pi_ci = input().split() Pi.append(pi_ci[0]) Ci.append(pi_ci[1]) poly = [] for i in range(n): poly.append(Ci[i] + 'x^'+Pi[i]) Pi.sort(reverse=True) newPoly = [] for i in range(n): for j in range(n): if Pi[i]==poly[j][3]: newPoly.append(poly[j]) print(' + '.join(newPoly))
Output:
Also Read:
- Hyphenate Letters in Python
- Earthquake in Python | Easy Calculation
- Striped Rectangle in Python
- Perpendicular Words in Python
- Free shipping in Python
- Raj has ordered two electronic items Python | Assignment Expert
- Team Points in Python
- Ticket selling in Cricket Stadium using Python | Assignment Expert
- Split the sentence in Python
- String Slicing in JavaScript
- First and Last Digits in Python | Assignment Expert
- List Indexing in Python
- Date Format in Python | Assignment Expert
- New Year Countdown in Python
- Add Two Polynomials in Python
- Sum of even numbers in Python | Assignment Expert
- Evens and Odds in Python
- A Game of Letters in Python
- Sum of non-primes in Python
- Smallest Missing Number in Python
- String Rotation in Python
- Secret Message in Python
- Word Mix in Python
- Single Digit Number in Python
- Shift Numbers in Python | Assignment Expert
- Weekend in Python
- Shift Numbers in Python | Assignment Expert
- Temperature Conversion in Python
- Special Characters in Python
- Sum of Prime Numbers in the Input in Python