Question

Problem 1 Substring matching is the process of determining whether shorter string (the substring) is contained...

Problem 1

Substring matching is the process of determining whether shorter string (the substring) is contained within a longer string. Substring matching plays important roles in the reconstruction of an unknown DNA string from pieces, and in searching for interesting substrings within a known DNA string.

Python provides a find (substring, start, end) string method that returns the lowest index (integer) where the substring is found in the index range start <= index < end. The start and end arguments are optional, but for this exercise we will make them required (you will learn later how to handle optional arguments). If the substring is not found, -1 is returned.

Without using the find string method, write a function name multi_find(some_string, sub_string, start, end) that, instead of returning one integer index, returns a string that contains zero or more indices separated by commas. In this case, the string will contain digits representing the integer indices. If the substring is not found, an empty string is returned.

output:

Please enter a string: this is a test string that tests are done on it successfully.

Please enter a substring: test

Please enter search starting index: 0

please enter search end index: 1000

found substrings: 10,27

would you like to continue (yes/no)? yes

This is a python problem. please help me to make this program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#code screenshot

#code

def multi_find(string, sub, start, end): #multi_find function implementation
found = "" #found string stores the indices
i = start
while(i<=end and i<len(string)): #loops through the str until i reaches end or string length
k = i  
for c in sub: #loops through sub substring and
if c == string[k]: #checks if the c matches with string[k]
k += 1 #if it matches then increments k value by 1
else: #else breaks the loop
break

if(k-i==len(sub)): #if k-i is equal to length of sub string
if(len(found)>0): #if length of found is greater than 0 then
found += "," #appends , to the found string
found += str(i) #append the index to found
i = i+k #increments i value by k
else:
i = i+1 #else adds i value by 1
return found

while(True): #loops unitl user enters no
#prompts the user for the values
s = input("Please enter a string: ")
sub = input("Please enter a substring: ")
start = int(input("Please enter search starting index: "))
end = int(input("Please enter search end index: "))
print("found substrings: ",multi_find(s, sub, start, end)) #calls the multi_find function
choose = input("would you like to continue(yes/no)?")
if(choose=="no"):
break
  
  

#output screenshot

#any query, post in the comment section

Add a comment
Know the answer?
Add Answer to:
Problem 1 Substring matching is the process of determining whether shorter string (the substring) is contained...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need answer in Python 3.8, with indentation and comments shown, please. 16.4* (Pattern matching) Write a...

    Need answer in Python 3.8, with indentation and comments shown, please. 16.4* (Pattern matching) Write a program that prompts the user to enter two strings and tests whether the second string is a substring in the first string. (Don't use the find method in the str class.) Analyze the time complexity of your algorithm. Here is a sample run of the program <output> Enter a string s1: Mississippi Enter a string s2: sip matched at index 6 <End Output>

  • Please write a function in C++ named nextString that will return a single 'value' (i.e. substring)...

    Please write a function in C++ named nextString that will return a single 'value' (i.e. substring) from a Comma Separated Value" string. Your function will take two arguments: a string variable containing a comma separated list of values, and an integer containing the starting index; your function should return a single string object with the value that starts at that index and ends right before the next comma ',' (do not include the comma in the returned string!) : string...

  • Task Algorithms: Pattern Matching (in java) Write a program that gets two strings from user, size...

    Task Algorithms: Pattern Matching (in java) Write a program that gets two strings from user, size and pattern, and checks if pattern exists inside size, if it exists then program returns index of first character of pattern inside size, otherwise it returns -1. The method should not use built-in methods such as indexOf , find, etc. Only charAt and length are allowed to use. Analyze the time complexity of your algorithm. Your solution is not allowed to be> = O...

  • Sequential Search Algorithm Python Programming Objectives ---------- * sequential search - design, analyze, implement, test, time...

    Sequential Search Algorithm Python Programming Objectives ---------- * sequential search - design, analyze, implement, test, time * continue practicing previously learned skills: algorithm analysis, graphing with theoretical prediction curves Implementation -------------- Write a function named sequential_search. It must have two parameters, a list to search and a value to search for. It must return either the index of the value within the list or -1 if the value is not found in the list. Your search function should NOT print...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • Detecting Substrings (C++ Version) Introduction A very common task that is often performed by programs that...

    Detecting Substrings (C++ Version) Introduction A very common task that is often performed by programs that work with text files is the problem of locating a specific substring within the file. I am sure we’ve all done this many times when working with Word, Notepad, or other editors. Since we don’t have a GUI or other means of displaying the contents of a file all at once, let’s modify the problem slightly. Rather than locating a specific substring within a...

  • In the first task, you will write a Java program that accepts a string of the...

    In the first task, you will write a Java program that accepts a string of the format specified next and calculate the answer based on the user input. The input string should be of the format dddxxdddxx*, where d represents a digit and x represents any character and asterisk at the end represents that the string can have any number of characters at the end. 1. Prompt the user to enter a string with the specific format (dddxxdddxx*) 2. Read...

  • JAVA programming 9.9 Ch 9, Part 2: ArrayList Searching import java.util.ArrayList; public class ArrayListSet {    ...

    JAVA programming 9.9 Ch 9, Part 2: ArrayList Searching import java.util.ArrayList; public class ArrayListSet {     /**      * Searches through the ArrayList arr, from the first index to the last, returning an ArrayList      * containing all the indexes of Strings in arr that match String s. For this method, two Strings,      * p and q, match when p.equals(q) returns true or if both of the compared references are null.      *      * @param s The string...

  • Goal:   Unscramble permuted words by generating all permutations of Jumble string and searching for a word...

    Goal:   Unscramble permuted words by generating all permutations of Jumble string and searching for a word in Unix dictionary. Unix Dictionary: dict.txt Details: Write a method called get_permutations that inputs a string like "dog". Your method should return an array of all permutations of the Jumble string. . For example: s = "dog" perms = get_permutations(a) print(perms) Output: ['dog', 'dgo', 'odg', 'ogd', 'gdo', 'god'] Rewrite the script for obtaining permutations and the end of the Comments, Hints, and Observersions section...

  • Use c-strings for the following project: Write a C++ program that declares an array containing up...

    Use c-strings for the following project: Write a C++ program that declares an array containing up to a maximum of 20 sentences, each sentence of maximum 81 characters long, using c-strings. Continue reading sentences from the user and store them in the array of sentences, until the user enters a NULL string for the sentence or 20 sentences have been entered. Then, one by one, display each sentence entered by the user and present the following menu of operations on...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT