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 returns...


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]


      print(isSorted(lyst))


      lyst = list(range(10))


      print(isSorted(lyst))


      lyst[9] = 3


      print(isSorted(lyst))



      True True True False







# Put your code here



# A main for testing your code

def main():

    lyst = []

    print(isSorted(lyst))

    lyst = [1]

    print(isSorted(lyst))

    lyst = list(range(10))

    print(isSorted(lyst))

    lyst[9] = 3

    print(isSorted(lyst))



if __name__ == "__main__":

    main()



Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here