Write code to check if the elements are in descending order
时间: 2024-03-11 10:46:58 浏览: 58
Sure, here's an example code snippet in Python to check if the elements of a list are in descending order:
```
def is_descending(lst):
for i in range(1, len(lst)):
if lst[i] > lst[i-1]:
return False
return True
```
This function takes a list `lst` as input and checks if its elements are in descending order. It does this by iterating over the list using a `for` loop and comparing each element to the previous one. If it finds an element that is greater than the previous one, it immediately returns `False`, indicating that the list is not in descending order. If it reaches the end of the list without finding any out-of-order elements, it returns `True`, indicating that the list is in descending order.
阅读全文