Question

Write the functions with the following headers:

# Return the reversal of an integer, e.g. reverse(456) returns
# 654
def reverse(number):

# Return true if number is a palindrome
def isPalindrome(number):

Use the reverse function to implement isPalindrome. A number is a palindrome if its reversal is the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome.

Solution

Verified
def reverse(num):
    '''Takes a positive int num, returns the int with reversed digits'''
    stringified_num = str(num)
    return int(stringified_num[::-1])

def isPalindrome(num):
    '''Takes a positive int num, returns true if num is a palindrome'''
    return reverse(num) == num

# Test
num = eval(input("Enter integer: "))
print(isPalindrome(num))

Create an account to view solutions

By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Continue with GoogleContinue with Facebook

Create an account to view solutions

By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Continue with GoogleContinue with Facebook

Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface 5th Edition by David A. Patterson, John L. Hennessy

Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionISBN: 9780124077263 (5 more)David A. Patterson, John L. Hennessy
220 solutions
Introduction to Programming Using Python 1st Edition by Y. Daniel Liang

Introduction to Programming Using Python

1st EditionISBN: 9780132747189Y. Daniel Liang
773 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777 (1 more)Ramez Elmasri, Shamkant B. Navathe
687 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848 (2 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
726 solutions

More related questions