Question
In Python: Write both a non-recursive and a recursive function that determines how many times a given letter occurs in a given string. Your program
In Python:
Write both a non-recursive and a recursive function that determines how many times a given letter occurs in a given string.
Your program should contain two functions, one that is non-recursive and one that is recursive. Your methods should take a string and a character as input, then return an integer representing number of occurrences.
Your program should also include the main program. Your main program should prompt the user for a string and then for a character to search for in that string. Output how many occurrences of that character were found in the string.
Example output might look like:
Enter a word: hello Enter a character to look for in that word: l There are 2 of l in hello Now searching recursively... There are also 2 of l in hello
Add comments to your program starting with your name at the top, then throughout your program to describe what you are doing. Be sure and make your calculations clear, giving your variables meaningful names. Also be sure to indent consistently throughout your program to make it more readable. Be sure you run this and test it a few times before submitting.
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