Question: PYTHON PROGRAMMING Hint: Depending on how you plan to solve this problem, accumulator variable initialized as an empty string may help in this question. Write
PYTHON PROGRAMMING
Hint: Depending on how you plan to solve this problem, accumulator variable initialized as an empty string may help in this question. Write a function called oPify, that takes a single string parameter (s) and returns a string. This function considers every pair of consecutive characters in s. It returns a string with the letters o and p inserted between every pair of consecutive characters of s, as follows. If the first character in the pair is uppercase, it inserts an uppercase O. If however, it is lowercase, it inserts the lowercase o. If the second character is uppercase, it inserts an uppercase P. If however, it is lowercase, it inserts the lowercase p. If at least one of the character is not a letter in the alphabet, it does not insert anything between that pair. Finally, if s has one or less characters, the function returns the same string as s. Do dir(str) and check out methods isalpha (by typing help(str.isalpha) in Python shell), and isupper
>>> TESTING CODE:
>>> oPify("aa")
aopa
>>> oPify("aB")
aoPB
>>> oPify("ooo")
oopoopo
>>> oPify("ax1")
aopx1
>>> oPify("abcdef22")
aopbopcopdopeopf22
>>> oPify("abcdef22x")
aopbopcopdopeopf22x
>>> oPify("aBCdef22x")
aoPBOPCOpdopeopf22x
>>> oPify("x")
x
>>> oPify("123456")
123456
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
