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.