logo CodeStepByStep logo

is_sorted

Language/Type: Python lists

Write a function named is_sorted that accepts a list of real numbers as a parameter and returns True if the list is in sorted (nondecreasing) order and False otherwise. For example, if lists named list1 and list2 store [16.1, 12.3, 22.2, 14.4] and [1.5, 4.3, 7.0, 19.5, 25.1, 46.2] respectively, the calls is_sorted(list1) and is_sorted(list2) should return False and True respectively. Assume the list has at least one element. A one-element list is considered to be sorted.

Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.