Write a program that prompts the user to enter two strings and then displays a m
ID: 3909832 • Letter: W
Question
Write a program that prompts the user to enter two strings and then displays a message indicating whether o not the first string ends with the second string. Your program must satisfy the following requirements 1. Your program must include a function called myEndsWith that takes two string parameters. This function returns True if the first string ends with the second string and returns False otherwise. 2. Your program must include a main function that prompts the user for the two strings, passes those strings to the myEndsWith function, and uses the value returned to display the correct message. 3. The message must be in the format "string-1" ends with/DOES NOT end with "string-2 Here are two example messages: "lowa City" ends with City" "lowa City DOES NOT end with "lowa 4. Your program may not use any methods from Python's str class.Explanation / Answer
def myEndsWith(s1,s2): #method to find whether 1st string ends with 2nd string
for i in range(len(s2)): #looping through the length of 2nd string
if s1[-i-1] != s2 [-i-1]: #checking whether elements are same from last
return False #if not equal returrn false
return True #if all equal return true
if __name__ == "__main__": #main function
print("Enter Strings: ")
s1 = input() #reading strings
s2 = input()
if myEndsWith(s1,s2): #calling method and if it returns true
print('"' + s1+ '"' + " ends with " + '"' + s2 + '"')
else: #if it returns false
print('"' + s1+ '"' + " DOES NOT ends with " + '"' + s2 + '"')
output:
Enter Strings:
lowa City
City
"lowa City" ends with "City"
Enter Strings:
lowa City
lowa
"lowa City" DOES NOT ends with "lowa"