給定多項式的係數儲存在列表中的計算多項式方程的 Python 程式
當需要計算多項式方程,而多項式的係數儲存在列表中時,可以使用簡單的“for”迴圈。
以下是同一演示:
示例
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)輸出
The polynomial equation for the given list of co-efficients is : 42
說明
定義了一個列表。
指定了一個數,並將列表的長度分配給一個變數。
結果變數被宣告為 0。
對列表的長度進行迭代,並將和新增到數中。
這作為輸出給出。
這顯示在控制檯上。
廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP