This is a school problem I encounter. I have written my code and it returns correct result. However, the test program shows checksum does not match. Below is the question and my code.
An element of items is said to be a "dominator" if every element to its right is strictly smaller than it. This function should count how many elements in the given list of items are dominators, and return that count. For example, in the list [42, 7, 12, 9, 2, 5], the elements 42, 12, 9 and 5 are dominators. By this definition, the last item of the list is automatically a dominator.
def count_dominators(items):
if len(items) ==0:
return len(items)
else:
k = 1
for i in range(1,len(items)):
if items[i]<items[i-1]:
k = k+1
else:
k = k+0
return k