Q. Write a program that prompts the user for two strings and checks if one of the strings is a prefix of the other. Print an appropriate message to inform the user which is the prefix of which or that neither is a prefix. For example, if the user input "evergreen" and "ever", the program would respond: "ever" is a prefix of "evergreen". But if the input was "evergreen" and "green", the program would respond that neither is a prefix of the other.

 

Answer = 

 

str = input ("Enter the word :- ")
pre = input ("Enter prefix :- ")
if str[ : len(pre)] == pre :
    print (pre, "is a prefix of ", str)
else :
    print (pre, "is not a prefix of ", str)

 

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post