← Back to Recursion
Question 611
Sorted Check By Recursion
Sorted Check By Recursion
Write is_sorted(values: list[int]) -> bool that returns True when every value is less than or equal to the one after it and False otherwise, by recursion: a list of length 0 or 1 is sorted; if the first value is greater than the second the list is not sorted; otherwise the answer is whether the rest of the list, the slice values[1:], is sorted. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line of integers separated by spaces (it may be empty), which the tests read into a list and pass to your function before printing the value it returns.
Expected Output:
True= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
RecursionSlicing
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.