CJCoding With Joseph
15free / daySign inCreate account

Character Tally By Recursion

Complete count_char(s: str, ch: str) -> int so it returns how many times the single character ch appears in the text s, by recursion. The base case is written: the empty string holds 0 matches. Add the recursive case: when the first character equals ch, return 1 plus the matches in the rest of the text, the slice s[1:]; otherwise return just the matches in the 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 value it returns.

Expected Output:

3

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
RecursionSlicing
📥 Auto-Input:
banana\na\n
This input is automatically fed to your program's stdin
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.