
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Compute Polynomial Equation from Coefficients in Python
When it is required to compute a polynomial equation when the coefficients of the polynomial are stored in a list, a simple ‘for’ loop can be used.
Below is the demonstration of the same −
Example
my_polynomial = [2, 5, 3, 0] num = 2 poly_len = len(my_polynomial) my_result = 0 for i in range(poly_len): my_sum = my_polynomial[i] for j in range(poly_len - i - 1): my_sum = my_sum * num my_result = my_result + my_sum print("The polynomial equation for the given list of co-efficients is :") print(my_result)
Output
The polynomial equation for the given list of co-efficients is : 42
Explanation
A list is defined.
A number is specified, and the length of the list is assigned to a variable.
A result variable is declared as 0.
The length of the list is iterated over, and the sum is added to the number.
This is given as the output.
This is displayed on the console.
Advertisements