← Back to Recursion
Question 592
Contains By Recursion
Contains By Recursion
Complete contains(values: list[int], target: int) -> bool so it returns True when target appears anywhere in values and False otherwise, by recursion. The base case is written: an empty list contains nothing. Add the recursive case: if the first value equals target return True; otherwise return whether the rest of the list, the slice values[1:], contains it. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: two lines, the list as integers separated by spaces (it may be empty) and then the target, which the tests read 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.