Download Python File:- Raw File | Download (Please rename it to .py file once downloaded, for it to run)

def alternating(l): if (len(l) > 1): if l[0] > l[1]: for i in range(len(l) - 1): if l[i] == l[i - 1]: return False if i % 2 == 0: if l[i] < l[i + 1]: return False if l[0] < l[1]: for i in range(len(l) - 1): if i % 2 == 0: if l[i] > l[i + 1]: return False return True def ascending(lst): for i in range(0, len(lst) - 1): if lst[i] > lst[i + 1]: return False return True def matmult(X, Y): col = len(Y[0]) row = len(X) result = [[0 for i in range(col)] for j in range(row)] for i in range(len(X)): for j in range(len(Y[0])): for k in range(len(Y)): result[i][j] += X[i][k] * Y[k][j] return result

Can be tested with the following code (Test Cases):-

>>> ascending([]) True >>> ascending([3,3,4]) True >>> ascending([7,18,17,19]) False >>> alternating([]) True >>> alternating([1,3,2,3,1,5]) True >>> alternating([3,2,3,1,5]) True >>> alternating([3,2,2,1,5]) False >>> alternating([3,2,1,3,5]) False >>> matmult([[1,2],[3,4]],[[1,0],[0,1]]) [[1,2],[3,4]] >>> matmult([[1,2,3],[4,5,6]],[[1,4],[2,5],[3,6]]) [[14, 32], [32, 77]]