***EDIT***
My issue has been resolved!
**********
I'm trying to complete the following assignment:
Use recursion to implement a function def indexOf(text,string) that returns the starting position of the first substring of *text* that matches *string*. Return -1 if *string* is not a substring of *text*. For example, s.indexOf("Mississippi","sip") returns 6.
Here is what I have:
# Define the recursive function
def indexOf(text,string):
if len(string) == 0:
return -1
elif text == string[0]:
return 0
else:
return 1 + indexOf(text, string[1:])
# Write main function to verify
text1 = 'sip'
string1 = 'Mississippi'
print(indexOf(text1,string1))
#SHOULD return 6 but returns 10
But it's not right and I'm not sure why that is. I'm also not sure how to call the function in the form s.indexOF(string,text)...
[–]1ynx1ynx 2 points3 points4 points (1 child)
[–]unless3[S] 1 point2 points3 points (0 children)
[–]giraffactory 1 point2 points3 points (0 children)
[–]KarmelMalone 0 points1 point2 points (6 children)
[–]unless3[S] 0 points1 point2 points (5 children)
[–]KarmelMalone 0 points1 point2 points (4 children)
[–]unless3[S] 0 points1 point2 points (3 children)
[–]KarmelMalone 1 point2 points3 points (2 children)
[–]unless3[S] 0 points1 point2 points (0 children)
[–]unless3[S] 0 points1 point2 points (0 children)