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 (e.g., s1+ s2).
the string replication operator (e.g.,s**n or n**s.
Python's built-in len, min and max functions.
Your solutions cannot use:
the in and not in operators (e.g., if s1 in s2:...);
slicing (e.g., slice = s[i : j]);
any of the methods provided by type str; for example, count, find, index, join, replace, rfind, rindex and many more.Exercise 3
Use the function design recipe to develop a function named has_pair. The function header (with missing type annotations) is: has_pair (s,ch). Parameter s is a string that has at least two characters. Parameter ch is a string containing exactly one character. The function returns True if s contains two occurrences of ch next to each other; otherwise it returns False.
For example, when has_pair is called this way: has_pair('abccd','c'), the function returns True, because 'abccd' contains a 'c' next to a 'c'. When has_pair is called this way: has_pair('abcdc','c'), the function returns False. Although 'abcdc' contains two occurrences of 'c', 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 has_pair.
For the exercises in Part A , your solutions can

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!