Question: For the exercises in Part A , your solutions can use: a for loop to iterate over the characters in a string. the string concatenation
For the exercises in Part A your solutions can use:
a for loop to iterate over the characters in a string.
the string concatenation operator eg s s
the string replication operator eg or
Python's builtin len, min and max functions.
Your solutions cannot use:
the in and not in operators eg if s in s:;
slicing eg slice si : j;
any of the methods provided by type str; for example, count, find, index, join, replace, rfind, rindex and many more.Exercise
Use the function design recipe to develop a function named haspair. The function header with missing type annotations is: haspair Parameter is a string that has at least two characters. Parameter ch is a string containing exactly one character. The function returns True if contains two occurrences of ch next to each other; otherwise it returns False.
For example, when haspair is called this way: haspairabccd the function returns True, because 'abccd' contains a next to a When haspair is called this way: haspairabcdcc the function returns False. Although 'abcdc' contains two occurrences of the first one isn't beside the second one.
Your function must have exactly one loop.
Your function definition must have type annotations and a complete docstring. Use the Python shell to test haspair.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
