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
An important safety precaution you should take before starting any electrical servicing job is to make sure that your
monitta
I'm pretty sure it's B. body is not grounded
5 0
3 years ago
Read 2 more answers
What is the role of the W3C? Group of answer choices oversee research and set standards for many areas of the Internet supervise
Murljashka [212]

Answer:

oversee research and set standards for many areas of the Internet

Explanation:

World Wide Web Consortium was created to maintain a standard order in the cyber world. It is an international community formed by the organizations as a member. W3C sets the standards of the websites and enables them to function and appear the same in every web browser. A specific standard of guidelines, rules, and protocols are fixed so that the World Wide Web can function and grow respectively.

5 0
3 years ago
Heelp my brainly stuff says i am 49 but im 11 how to fix?X??
stich3 [128]

Make another account. But u cant get into brainly unless u r over 26 or something.

6 0
3 years ago
Somehow I lost 1000 points!!! Does anyone know what happened? Is it possible that I was hacked? ​
Dima020 [189]

Answer:

Explanation:

You most likely lost 1000 points because you cheated to get them if not there is a possibility you were.

6 0
3 years ago
Read 2 more answers
(10 points) 5.12. Discuss how the following pairs of scheduling criteria conflict in certain settings. a. CPU utilization (effic
Novosadov [1.4K]

Answer:

Check the explanation

Explanation:

  1. CPU utilization and response time: CPU utilization is amplified if the overheads that are connected with context switching or alternating are minimized. The context switching outlay can be reduced by performing context switches occasionally. This could on the other hand lead to increasing the response time for processes.
  2. The Average turnaround time and maximum waiting time: Average turnaround time is reduced by implementing the shortest or simple tasks first. Such a scheduling and arrangement strategy could nevertheless starve long-running tasks and in so doing boost their overall waiting time.
  3. I/O device utilization and CPU utilization: CPU utilization is maximized by executing a list of long-running CPU-bound tasks not including the performing context switches. This is maximized by setting up I/O-bound tasks as early as they become ready to run, thus sustaining the overheads of context switches.

3 0
3 years ago
Other questions:
  • Row array gameScores contains all player scores. Construct a row array highScores than contains all player scores greater than m
    15·1 answer
  • Peak download rate for a 4g network is __________. select one:
    12·2 answers
  • My computer have black spots and line
    7·2 answers
  • 2) Complete the get_num_of_characters() function, which returns the number of characters in the user's string. We encourage you
    11·1 answer
  • How do you change the text style on brainly mobile ?
    12·1 answer
  • A specialized security administrator responsible for performing systems development life cycle (SDLC) activities in the developm
    11·1 answer
  • You have created a new dhcp scope with address range 192.168.1.1 to 192.168.1.254. you have five servers configured with static
    9·1 answer
  • Persuasion is when Someone speaks to crowd about love <br>○True<br>○False​
    10·1 answer
  • A company is developing a smart TV that connects to a wireless home network. Which technology can best help to establish this co
    11·2 answers
  • How can the system administrator give the executive assistant the ability to view, edit, and transfer ownership of all records,
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!