خرید بک لینک

Vote count: 0

The function derivative computes the derivative of a polynomial; the degree of each entry needs to be reduced by one, each entry must be multiplied by the previous degree, and the term at degree[0] needs to be removed.

This code

lst = [1,2,3] """This list represents the polynomial 3x^2+2x+1"""

"""This function moves each entry one index down and removes the last 
entry"""

def move(lst):
    copy = list(lst)
    for i in range(len(lst)):
        lst[i-1] = copy[i]
    del lst[-1]
    print lst

move(lst)

produces this:

Samuels-MacBook:python baicle$ python problemset2.py
[2, 3]

This code:

def derivative(poly):
    copy = list(poly)
    degree = 0
    for i in range(len(poly)):
        i = degree*(i+1)
        poly[i-1] = copy[i]
        degree += 1
    del poly[-1]
    print poly

derivative(lst)

produces this error:

Samuels-MacBook:python baicle$ python problemset2.py

     Traceback (most recent call last):   File "problemset2.py", line 59,
     in <module>
         derivative(lst)   File "problemset2.py", line 55, in derivative
         poly[i-1] = copy[i] IndexError: list index out of range

asked 6 mins ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 18 خرداد 1395 ساعت: 15:14

صفحه بندی