Question: def myAppend ( str , ch ) : # Return a new string that is like str but with character ch added at the end

def myAppend(str, ch): # Return a new string that is like str but with character ch added at the end return str + ch def myCount(str, ch): # Return the number of times character ch appears in str. count =0 for char in str: if char == ch: count +=1 return count def myExtend(str1, str2): # Return a new string that contains the elements of str1 followed by the elements of str2 return str1+ str2 def myMin(str): # Return the character in str with the lowest ASCII code. if len(str)==0: print("Empty string: no min value") return None min_char = str[0] for char in str: if char < min_char: min_char = char return min_char def myInsert(str, i, ch): # Return a new string like str except that ch has been inserted at the ith position. if i > len(str): print("Invalid index") return None return str[:i]+ ch + str[i:] def myPop(str, i): # Return two results: a new string with the ith element removed, and the value that was removed. if i >= len(str): print("Invalid index") return str, None removed_char = str[i] new_str = str[:i]+ str[i+1:] return new_str, removed_char def myFind(str, ch): # Return the index of the first (leftmost) occurrence of ch in str, if any. Return -1 if ch does not occur in str. for i in range(len(str)): if str[i]== ch: return i return -1 def myRFind(str, ch): # Return the index of the last (rightmost) occurrence of ch in str, if any. Return -1 if ch does not occur in str. for i in range(len(str)-1,-1,-1): if str[i]== ch: return i return -1 def myRemove(str, ch): # Return a new string with the first occurrence of ch removed. If there is none, return str. index = str.find(ch) if index !=-1: return str[:index]+ str[index+1:] return str def myRemoveAll(str, ch): # Return a new string with all occurrences of ch removed. If there are none, return str. return str.replace(ch,'') def myReverse(str): # Return a new string like str but with the characters in the reverse order. return str[::-1] # Test cases s1= "abcd" s2= "efgh" print(myAppend(s1,"e")) # 'abcde' print(myCount(s1,"e")) # 0 print(myCount(s1,"a")) # 1 print(myCount("abcabc","a")) # 2 print(myExtend(s1, s2)) # 'abcdefgh' print(myMin("")) # Empty string: no min value print(myMin("zqralm")) # 'a' print(myMin("Hello World!")) # '' print(myInsert("abc",0,"d")) # 'dabc' print(myInsert("abc",2,"d")) # 'abdc' print(myInsert("abc",4,"d")) # Invalid index print(myPop("abcd",1)) # ('acd','b') print(myPop("abcd",0)) # ('bcd','a') print(myPop("abcd",5)) # Invalid index print(myFind("abcdabcd","a")) # 0 print(myFind("abcdabcd","c")) # 2 print(myFind("abcdabcd","f")) # -1 print(myRFind("abcdabcd","d")) # 7 print(myRFind("abcdabcd","e")) # -1 print(myRemove("abcdabcd","a")) # 'bcdabcd' print(myRemove("abcdabcd","x")) # 'abcdabcd' print(myRemove("abcdabcd","d")) # 'abcabcd' print(myRemoveAll("abcabcabca","a")) # 'bcbcbc' print(myReverse("abcd")) # 'dcba' print(myReverse("")) # ''

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!