Question
Write a Python function, sscount0, that returns the number of times that a substring occurs in another string. Function sscount0 should have two parameters, needle,
Write a Python function, sscount0, that returns the number of times that a substring occurs in another string. Function sscount0 should have two parameters, needle, the substring to search for, and haystack, the string to search in. Function sscount0 should use only the string slice operation (along with other Python tools, e.g., for loop, conditional) no string methods to implement this functionality.For example,
>>> sscount0('sses', 'assesses')
2
>>> sscount0('!!!', '!!!!!')
3
Next, write a revised version of sscount0. Function sscount1 should use the string method startswith (along with other Python tools, e.g., for loop, conditional) to implement the same functionality as sscount0.
Finally, add code at the beginning of the Python file to import the Python doctest module, and add code at the end of the file to call the testmod function from doctest: print(doctest.testmod()). Include the examples given above and two more examples of calls to sscount in the docstrings of each of the sscount functions.
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