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]
3 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]3 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 do I do these? I dont understand.
Natalija [7]
I don’t understand either, I would suggest contacting your teacher or maybe searching up videos or tutorials on how to solve such a problem.
3 0
3 years ago
Which of the following can track your pulse and heart rate, as well as accept calls and display notifications from a smartphone?
alexgriva [62]
The answer is a smart watch most likely the apple or Samsung versions both now offer voice calls and health tracking sensors on the bottom side of the watch most popular is the apple as the company grows more everyday
8 0
3 years ago
A(n) _____ measures the ability to juggle a variety of demands, as in a manager's job where the candidate is presented with simu
Tju [1.3M]

Answer: in-basket test

Explanation:

An in-basket test or an in-basket exercise is a test used by firms or governments in recruiting and promoting employees. During the test, job applicants receive some mails, telephone calls, documents and memos.

3 0
4 years ago
Which top-level domain can be used by anyone, regardless of their affiliation?
Firdavs [7]

Answer:

C. org

Explanation:

org is an open domain so anyone is allowed to register a .org domain

7 0
3 years ago
If you wish to maintain a consistent style to all the documents you create, it would be helpful to use a _​
kakasveta [241]

Answer:Apply a consistent look across the whole document instead of having to format each section individually.Automatically number section headers.Apply same font to the entire text body.Apply the same font to header sections.Use a consistent paragraph spacing.Pick a default color scheme for SmartArt, charts, and shapes.Pick from a number of pre-designed styles use them as your own and modify them.

Read more on Webcache.googleusercontent.com - https://webcache.googleusercontent.com/question/1639566#readmore

Explanation:

tht is the answer

7 0
3 years ago
Other questions:
  • Write a program that takes nouns and forms their plurals on the basis of these rules:
    8·1 answer
  • A software programâs _________ indicates what can legally be done with that program.]
    5·1 answer
  • In a proper webpage, which tag holds all of a webpages visible HTML?
    5·1 answer
  • Why is investing in a mutual fund less risky than investing in a particular company's stock? A. Mutual funds only invest in blue
    14·2 answers
  • A security manager has discovered that sensitive information stored on a server has been compromised. The organization is requir
    7·1 answer
  • The UNIX system does not attempt to avoid cycles. Instead, it restricts access to the linking capability of the system. Normal u
    11·1 answer
  • Many Web browsers allow users to open anonymous windows. During a browsing session in an anonymous window, the browser does not
    14·1 answer
  • What is this car first to awnser is the brianliest
    5·2 answers
  • Combining data and code in a single object is known as
    7·1 answer
  • ________ is a technique where the general characteristics are kept and the details are hidden.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!