I am not sure I even fully understand the second half of this question. I will post the question I'm stuck on, and the code I have so far. At the moment Module 2 is the same as Module 1, as a place holder so i could test my menu function.
Please forgive my formatting, this is my first post.
Question: From the knowledge learned throughout the course write a menu-driven palindrome check using two functions. One function will compare the first letter to the last letter working its way to the center. The second function will break the work in two. The first half will be compared to the mirror image of the second half to determine if the word is a palindrome. Please note the functions must work for even and odd number of letter strings. Your submission must be able to compare the words deed as well as Dad.
My Code so far:
Module 1 Recursive Algorithm
def isPalindrome(string) :
if len(string) <= 1 :
return True
if string[0] == string[len(string) - 1] :
return isPalindrome(string[1:len(string) - 1])
else :
return False
Module 2 divide word method
def isPalindrome2(string) :
if len(string) <= 1 :
return True
if string[0] == string[len(string) - 1] :
return isPalindrome2(string[1:len(string) - 1])
else :
return False
print( "Please think of a word to test and select a method")
print("1) Using compare letters method")
print("2) Using dividing word in half method and comparing")
print("3) Quit")
choice = input("Select option: #")
if choice == '1':
st = input("Enter word you wish to test: ")
if (isPalindrome(st)) :
print ("Option #1, The word: "+ st +", is a palendrome")
else :
print ("Option #1, The word: "+ st +", is NOT a palendrome")
elif choice =='2':
st = input("Enter word you wish to test: ")
if (isPalindrome2(st)) :
print ("Option #2, The word: "+ st +", is a palendrome")
else :
print ("Option #2, The word: "+ st +", is NOT a palendrome")
elif choice == '3':
print("You quit.")
exit()