All problems
Simple Moving Average Endpoint
Problem
Compute the simple moving average of the last k observations in a series, that is, the mean of series[-k:].
Return 0.0 when k is not positive or when k exceeds the length of the series.
Hint
Only the tail of the series participates in the average.
Test cases
case 1
in: [[1,2,3,4,5],3]
expected: 4
case 2
in: [[10,20],1]
expected: 20
case 3
in: [[1,2],5]
expected: 0
case 4
in: [[],2]
expected: 0
Starter codePython
def sma_endpoint(series, k):
# Your code here
pass4 test cases · run your code against them in the editor