1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
PtichkaEL [24]
2 years ago
14

#Write a function called string_finder. string_finder should #take two parameters: a target string and a search string. #The fun

ction will look for the search string within the #target string. # #The function should return a string representing where in #the target string the search string was found: # # - If search string is at the very beginning of target # string, then return "Beginning". For example: # string_finder("Georgia Tech", "Georgia") -> "Beginning" # # - If search string is at the very end of target string, # then return "End". For example: # string_finder("Georgia Tech", "Tech") -> "End" # # - If search string is in target string but not at the # very beginning or very end, then return "Middle. For # example: # string_finder("Georgia Tech", "gia") -> "Middle" # # - If search string is not in target string at all, then # return "Not found". For example: # string_finder("Georgia Tech", "Idaho") -> "Not found" # #Assume that we're only interested in the first instance #of the search string if it appears multiple times in the #target string, and that search string is definitely #shorter than target string. # #Hint: Don't be surprised if you find that the "End" case #is the toughest! You'll need to look at the lengths of #both the target string and the search string. #Write your function here!

Computers and Technology
1 answer:
adoni [48]2 years ago
6 0

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"

You might be interested in
How is the phrase "employability skills" defined?
Digiron [165]

Answer:

Problem-solving. Why is problem-solving so valued? Companies face a lot of obstacles. Those better able to cope

Explanation:

7 0
2 years ago
Read 2 more answers
Dawn needs to insert a macro into a Word document. Where can she find the Insert Macro dialog box?
amid [387]

Answer:

Developer tab

Explanation:

Inserting the Macro dialog box can be confusing for many people because the "Developer tab," where it can be found, is <em>hidden by default</em> in Microsoft Word. In order to add this to the ribbon, all you have to do is to go to the File tab, then click Options. After this, click Customize Ribbon. Under this, choose Main Tabs, then select the Developer check box. The Developer tab will then become visible. You may now insert a macro.

6 0
2 years ago
A loop should output 1 to n. If n is 5, the output is 12345. What should XXX and YYY be? Choices are in the form XXX / YYY. cin
Alona [7]

Answer:

i = 0; i < n / i + 1

Explanation:

Given that:

a loop output 1 → n

if n = 5

output = 12345

n = scnr.nextInt();

for (XXX;  i++)

{

System.out.printIn(YYY);

}

XXX / YYY is i = 0; i < n / i + 1

5 0
2 years ago
Read 2 more answers
Example of AI in online shopping<br>​
Doss [256]

Answer:

hope it's help you ok have a good day

8 0
2 years ago
Examples of intermediate technology​
Effectus [21]

Example of intermediate technology is the treadle pump, which enables farmers to provide a greater amount of water to their plants more easily compared to watering by bucket, while requiring much less infrastructure than constructing irrigation dams and pipes.

3 0
2 years ago
Read 2 more answers
Other questions:
  • Which is true regarding pseudocode?
    9·2 answers
  • When you take a multiple-choice test, you are relying on ________, a means of retrieving information out of your long-term memor
    8·1 answer
  • Typically, you need to score _____ or higher on an AP exam to receive college credit for the AP course in the subject tested by
    11·2 answers
  • To remove white space, double-click this icon.
    9·1 answer
  • Suppose barriers to entry exist in the telecommunications industry. This best describes a _____ market.
    12·1 answer
  • You have been asked to create a query that will join the Production.Products table with the Production.Categories table. From th
    6·1 answer
  • Methods that require you to use an object to call them are called ____ methods.1. accessor
    7·1 answer
  • A slow response when opening applications or browsing the Internet, applications that do not work properly, an operating system
    5·2 answers
  • at the grocery store alexa by 1 1/3 lb of ground turkey nasha by two times as much ground turkey is alexa how much ground turkey
    9·1 answer
  • Please explain what steps you will take to prevent hackers from getting access to your personal information.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!