python 3.xx Recursion An \'array palindrome\' is an array, which, when its eleme
ID: 3823446 • Letter: P
Question
python 3.xx
Recursion
An 'array palindrome' is an array, which, when its elements are reversed, remains the same.
Write a recursive function, isPalindrome, that accepts a tuple and returns whether the tuple is a palindrome.
A tuple is a palindrome if:
*the tuple is empty or contains one element
*the first and last elements of the tuple are the same, and the rest of the tuple is a palindrome
Explanation / Answer
number = int(raw_input("Enter a number: ")) rev = 0 neg = number original = number if (number < 0): number = number * -1 else: number = number while ( number > 0 ): k = number % 10 number = number / 10 rev = k + ( rev * 10 ) if (number < 1): break if ( neg < 0 ): rev = ( rev * -1) else: rev = (rev) if ( rev == original): print "The number you entered is a palindrome number" else: print "The number you entered is not a palindrome number"Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.