Answer:
I am writing a Python program:
def string_finder(target,search): #function that takes two parameters i.e. target string and a search string
position=(target.find(search))# returns lowest index of search if it is found in target string
if position==0: # if value of position is 0 means lowers index
return "Beginning" #the search string in the beginning of target string
elif position== len(target) - len(search): #if position is equal to the difference between lengths of the target and search strings
return "End" # returns end
elif position > 0 and position < len(target) -1: #if value of position is greater than 0 and it is less than length of target -1
return "Middle" #returns middle
else: #if none of above conditions is true return not found
return "not found"
#you can add an elif condition instead of else for not found condition as:
#elif position==-1
#returns "not found"
#tests the data for the following cases
print(string_finder("Georgia Tech", "Georgia"))
print(string_finder("Georgia Tech", "gia"))
print(string_finder("Georgia Tech", "Tech"))
print(string_finder("Georgia Tech", "Idaho"))
Explanation:
The program can also be written in by using string methods.
def string_finder(target,search): #method definition that takes target string and string to be searched
if target.startswith(search): #startswith() method scans the target string and checks if the (substring) search is present at the start of target string
return "Beginning" #if above condition it true return Beginning
elif target.endswith(search): #endswith() method scans the target string and checks if the (substring) search is present at the end of target string
return "End"
#if above elif condition it true return End
elif target.find(search) != -1: #find method returns -1 if the search string is not in target string so if find method does not return -1 then it means that the search string is within the target string and two above conditions evaluated to false so search string must be in the middle of target string
return "Middle" #if above elif condition it true return End
else: #if none of the above conditions is true then returns Not Found
return "Not Found"