- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to compute a Polynomial Equation
When it is required to compute a polynomial equation, a simple iteration along with the ‘*’ operator is used.
Example
Below is a demonstration of the same
my_list = [3, -6, 3, -1, 23, -11, 0, -8] print("The list is :") print(my_list) x = 3 my_list_length = len(my_list) my_result = 0 for i in range(my_list_length): my_sum = my_list[i] for j in range(my_list_length - i - 1): my_sum = my_sum * x my_result = my_result + my_sum print("The result is :") print(my_result)
Output
The list is : [3, -6, 3, -1, 23, -11, 0, -8] The result is : 3349
Explanation
A list is defined and is displayed on the console.
A variable is assigned an integer value.
The length of the list is assigned to a variable.
A variable is initialized to 0.
The list is iterated over, and the elements are assigned to a variable.
The list is iterated again, and the variable previously used is multiplied with the integer previously defined.
The variable initialized to 0 is added to the integer.
This is the output that is displayed on the console.
Advertisements