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
Kevin needs to get his data from a database into a text file to send to another group. He needs to _____.
Rasek [7]
A.Export

I got it right on test
6 0
2 years ago
Read 2 more answers
A friend is having a problem with keeping a fish tank at the right temperature so the fish stay healthy. Describe how you could
omeli [17]

Answer:

water temperature gauge sensor

Explanation:

  • We can connect a temperature sensor connected to the water and a heater or cooler sensor, we have created a program to check the temperature from the sensor.
  • when the water is hotter than recommended, we turn on the refrigerator and when it is cold, we turn on the heater
  • so correct answer is water temperature gauge sensor

4 0
2 years ago
TV show information can either keep track of the number of viewers per show or the name of a show. Information is kept in a file
Elza [17]

Answer:

See explaination for Program source code.

Explanation:

The program source code below.

#include <iostream>

#include <fstream>

#include <vector>

using namespace std;

class Show

{

private:

string title;

int viewers;

public:

Show()

{

this->title = "";

this->viewers = 0;

}

Show(string title, int viewers)

{

this->title = title;

this->viewers = viewers;

}

string getTitle(){ return this->title; }

int getViewers(){ return this->viewers; }

};

int main()

{

vector<Show> shows;

vector<string> titles;

vector<int> viewers;

ifstream inFile1("file1.txt");

ifstream inFile2("file2.txt");

string line1, line2;

if(!inFile1.is_open() || !inFile2.is_open())

{

cout << "Either of the files could not be found!\n";

exit(0);

}

getline(inFile1, line1);

if(line1.compare("Show") == 0)

{

while(getline(inFile1, line1))

{

titles.push_back(line1);

}

inFile1.close();

}

getline(inFile2, line2);

if(line2.compare("Viewer") == 0)

{

while(getline(inFile2, line2))

{

viewers.push_back(stod(line2));

}

inFile2.close();

}

for(int i = 0; i < titles.size(); i++)

{

shows.push_back(Show(titles[i], viewers[i]));

}

// display all the show details

cout << "\nALL SHOWS:\n----------\n";

for(Show show : shows)

{

cout << "Title: " << show.getTitle() << ", Number of viewers: " << show.getViewers() << endl;

}

cout << endl;

return 0;

}

See attachment for output

3 0
3 years ago
Please help me with this
Masteriza [31]

Answer:

Explanation:

what?

6 0
3 years ago
The prepaid tuition plan covers
rusak2 [61]
Hey there!

A prepaid tuition plan is a plan that allows you to pay the current rate of tuition now (say, years in advance), even if it's much higher than the time when the payment for tuition would actually be paid. This plan is great for anyone who wants to pay a lower price for high–cost education now (even if their kid isn't college age yet) and not have to worry about economic standing or inflation in the future that could drive the tuition prices up. 

The plan only covers tuition and other similar fees. You can not purchase books or room and board with it in advance. So, your answer should be: C. Tuition and Fees. 

Hope this helped you out! :-)
8 0
3 years ago
Read 2 more answers
Other questions:
  • If you quote an author from a website in a paper, it will be important to create a _____ in your writing to give them credit for
    7·2 answers
  • Your assignment is to write an assembly language program which read a string and print it in uppercase. This program asks the us
    15·1 answer
  • What are the first two lines of defense a company should take when addressing security risks?
    10·1 answer
  • Before his job interview, Shabnam took the time to carefully wash and iron his best khaki pants and a button-down shirt. He even
    15·2 answers
  • Where should you click to edit an existing formula?
    12·2 answers
  • Why is it NOT a good practice to save everything on the desktop?
    6·2 answers
  • Match the job description to the level of degree it requires.
    15·1 answer
  • You attempt to telnet to system 192.168.1.240. You receive the following message: "Connecting To 192.168.1.240...Could not open
    5·1 answer
  • You need to replace a broken monitor on a desktop system. You decide to replace it with a spare monitor that wasn't being used.
    15·2 answers
  • What are good reasons to do yearly disaster recovery testing? check all that apply
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!