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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started