def is_sorted(values):
# Add code here!
pass
# Ascending order
got = is_sorted([1, 2, 3])
assert got is True, f"[1, 2, 3]: expected True, got {got!r}"
# Descending order
got = is_sorted([3, 2, 1])
assert got is False, f"[3, 2, 1]: expected False, got {got!r}"
# Equal neighbors still count as ascending
got = is_sorted([1, 2, 2, 3])
assert got is True, f"[1, 2, 2, 3]: expected True, got {got!r}"
# The list you receive stays as it was
numbers = [3, 1, 2]
is_sorted(numbers)
assert numbers == [3, 1, 2], f"Input changed: {numbers!r}"
# Your case: which list is most likely to break it?
# got = is_sorted(___)
# assert got is ___, f"expected ___, got {got!r}"Check whether a list is sorted
Write a Python function is_sorted(values) that returns True when a list of numbers is in ascending order, allowing equal neighboring values, and False otherwise. Do not change the list you receive. Python has a built-in sorted function, but for this exercise use a loop to compare neighboring values. Do not use sorted or the list’s sort method.
You may use the starter code in Listing 1. Run the supplied tests, then add one test case of your own and state its expected result.