Answered You can hire a professional tutor to get the answer.

QUESTION

#The portion of code below does not pass the test cases listed at the end. Other classmates have been receiving the same errors.

#The portion of code below does not pass the test cases listed at the end. Other classmates have been receiving the same errors.

#AT THIS POINT, I'M BEYOND CONFUSED WITH THIS QUESTION

#The original directions ask us to take two strings , and returns what is left over if 

#the second string is removed from the first. 

#The second string to be removed is guaranteed to be less than four letters long.

def remove(l1,l2):

string1 = l1

string2 = l2

ctr = -1 #tracks index in l1

for i in range(len(l1)): #scours l1 and uses index tracking

if l1[ctr] == l2[0]: #checks if the first letters are the same

ctr = i #then assign i to counter

for j in range(1,len(l2)): #checks the rest of l2

if l2[j] != l1[i + j]: #when letters don't match

ctr = -1

break 

if ctr != -1:

string1 = l1[0:ctr] + l1[ctr + len(l2):len(l1)]

break

return string1

#test cases:

remove (bird, cat)

#expect: bird

remove (bird, i)

#expect: brd

remove (bird, bi)

#expect: rd

remove (birdbirdbikd, ir)

#expect: bdbdbikd

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question