Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using python, Define a function substring(word1, word2, pos) which returns True

ID: 3762146 • Letter: U

Question

Using python, Define a function substring(word1, word2, pos) which returns True if word1 is a substring of word2 starting from position pos. Otherwise, it returns False. Create a program that asks the user to input two words and an integer from the keyboard, then call the function substring(word1, word2, pos). If the first word is a substring of the second word starting from pos, print a line “xxxx is contained in yyyy starting from zzzz”, where xxxx is the first word, yyyy is the second word, and zzzz is the position. Otherwise, print “ xxxx is not contained in yyyy starting from zzzz.”

Explanation / Answer

def substring(word1, word2, pos):
   if word1 in word2[pos:]:
       print(word1+" is contained in "+word2+" starting from "+str(pos))
   else:
       print(word1+" is not contained in "+word2+" starting from "+str(pos))
      
a = input('Enter string 1: ')
b = input('Enter string 2: ')
c = input('Enter an integer: ')
substring(a, b, int(c))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote