← Back to Recursion
Question 620
Remove A Letter
Remove A Letter
Write remove_char(s: str, ch: str) -> str that returns the text s with every copy of the single character ch removed, by recursion and without .replace(): the empty string stays empty; when the first character equals ch, return the cleaned rest of the text (the slice s[1:]) with nothing added; otherwise return the first character followed by the cleaned rest. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: two lines, the text (it may be empty) and then the character, which the tests read and pass to your function before printing the string it returns (an empty result prints as a blank line).
Expected Output:
bnn= 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.