Write code to check if the elements are in descending order
时间: 2024-03-11 21:46:58 浏览: 62
asm.rar_The Show_score board
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.
阅读全文