Question: (IN PYTHON) Write a function count_8s(string) that performs the following actions: Receives a single parameter called string that we expect to be a string. If
(IN PYTHON)
Write a function count_8s(string) that performs the following actions:
Receives a single parameter called string that we expect to be a string.
If we receive something that is NOT a string, raise a TypeError with the message Non-string input received.
Uses recursion to count the number of eights in the string.
Use a string of length 0 as your base case.
Otherwise, determine if the first character in string is 8 or not, and call count_8s() again with the rest of the string as an argument.
Returns the number of eights found in the string.
NOTE: You are not to use a while or for loop in your code.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
