I am trying to write a function that will test whether or not a list is in decending order. This is what I have so far, but it doesn’t seem to be working for all lists.
I used the list [9,8,5,1,4,3,2] and it returned 'true'.
I can’t seem to figure out where my mistake is.
def ordertest(A):
n = len(A)
for i in range(n):
if A[i] >= A[i+1]:
return 'true'
else:
return 'false'
You should rather do the reverse check (As soon as you get
A[i] < A[i+1], return false