Question: Write a function named is_sorted that takes a list of numbers and returns True in case the list is in increasing order, and False otherwise.
Write a function named is_sorted that takes a list of numbers and returns True in case the list is in increasing order, and False otherwise.
This means that every number in the list should be larger or the same as the preceding number.
By convention, we will return True for the empty list. For example:
>>> is_sorted ([]) True >>> is_sorted ([1]) True
>>> is_sorted ([1 , 2 , 3]) True >>> is_sorted ([1 , 2 , 2 , 3]) True >>> is_sorted ([1 , 2 , 2 , 1]) False
Hint: notice that a list is sorted just in case there is no adjacent pair of entries that is out of order. In other words, a list is sorted if for every adjacent pair of entries, the one on the left is less than or equal to the one on the right.
Note: for the purposes of this problem, you may not use any of Pythons built-in sorting functions, instead, you should traverse the list and check that all adjacent pairs of entries are ordered.
Your function should not use print or input at all. Test your code thoroughly before submitting it.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
