Adapt the code so that the user is continually
asked to test whether no not some text that they enter is a palindrome until the user
enters the letter ’Q’ or ’q’.
The output should look something like this:
Enter some text to test to see if it is a palindrome . Enter ’Q’ to quit :
madam Is " madam " a palindrome ? True
Enter some text to test to see if it is a palindrome . Enter ’Q’ to quit :
David
Is " David " a palindrome ? False
Enter some text to test to see if it is a palindrome . Enter ’Q’ to quit :
Rise to vote , Sir
Is " Rise to vote , Sir " a palindrome ? True
Enter some text to test to see if it is a palindrome . Enter ’Q’ to quit :
Q
Process finished with exit code 0
__author__ = ’ davidbrowning ’
‘‘‘ SN 12345678 ’’’
def reverse ( text ):
return text [:: -1]
def isPalindrome ():
text = input (’Enter possible palindrome : \n’)
print (’Is ’,text ,’a palindrome ?’,text == reverse ( text ))
’’’ Checking to see if text is a palindrome should ignore punctuation ,
white space and case . What needs to be
1
Expert's answer
2014-04-07T13:43:02-0400
__author__ = ' davidbrowning ' ''' SN 12345678 '''
import sys
def reverse ( text ): return text [:: -1]
def isPalindrome (): text = input ('Enter possible palindrome : \n') text = text.upper().replace(' ', '') if text == 'Q': sys.exit() print ('Is ', text, 'a palindrome ?', text == reverse(text))
Comments
Leave a comment