Oct-15-2017, 03:28 AM
defining a function that 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
-if the first character in the pair is uppercase, it inserts an uppercase O, if it's lowercase, it inserts the lowercase o.
-if the second character is uppercase, it inserts an uppercase P, if it's 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.
-if s has one or less characters, the function returns the same string as s.
This is how far I got to tackling this problem, although it doesn't give what is expected (after my code below there are some examples of what the function should do)
>>> 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’
-if the first character in the pair is uppercase, it inserts an uppercase O, if it's lowercase, it inserts the lowercase o.
-if the second character is uppercase, it inserts an uppercase P, if it's 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.
-if s has one or less characters, the function returns the same string as s.
This is how far I got to tackling this problem, although it doesn't give what is expected (after my code below there are some examples of what the function should do)
def oPify(s): newS= '' if s<=1: return s for i in s: newS = newS + s[i] + 'op' return newSExamples:
>>> 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’