A list is sorted in ascending order if it is empty or each item except the last one is less than or equal to its successor. Define a predicate isSorted that expects a list as an argument and returnsTrue if the list is sorted, or returnsFalse otherwise.
(Hint: For a list of length 2 or greater, loop through the list and compare pairs of items, from left to right, and return False if the first item in a pair is greater.)
Below is an example of a main function and the associated output:
def main():
lyst = []
print(isSorted(lyst))
lyst = [1]
lyst = list(range(10))
lyst[9] = 3
True True True False
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here