Question: Create a Python program insert.py containing a function insert_inbetween(s,p) that returns a new string containing all characters in string s separated with string/character p. That
Create a Python program insert.py containing a function insert_inbetween(s,p) that returns a new string containing all characters in string s separated with string/character p. That is, for input abcd,+ it should return a+b+c+d, and for input Alice, FF it should return AFFlFFiFFcFFe. Input strings s with zero or one character should be returned as they are. Also, add program code that demonstrates how the function can be used.
This is not Working Very Well
def insert_between(s,p): if len(s)<2: return s newStr="" for i in range(0,len(s)-1): newStr=newStr+s[i]+p newStr=newStr+s[len(s)-1] return newStr
print(insert_between("abcd",'+')) print(insert_between("Alice","FF")) print(insert_between('A','+'))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
