Why is this code not working python nbspi dont think the


Question:

def sma(list1,n):

"""Returns simple moving average of a list of numbers in size n"""

count = 0

result = [0]*(len(list1)-n+1)

for item in range(len(result)):

result[count] = arithmetic_mean(list1[count:count+n])

count += 1

print count

return result

why is this code not working? (python)  I dont think the for loop is going through because counter never goes off 1.

For example, sma([5, 2, 8, 3, 7, 4], 3) should return [5, 4.3333333, 6, 4.666667], which consists of four averages: (5+2+8)/3, (2+8+3)/3, (8+3+7)/3, and (3+7+4)/3. Note that if the length of the input list is less than or equal to n, then the result list contains just one number, the list's mean.

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Why is this code not working python nbspi dont think the
Reference No:- TGS01272655

Expected delivery within 24 Hours