Related questions with answers
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
Verifieddef 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
Create an account to view solutions
By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface
5th Edition•ISBN: 9780124077263 (5 more)David A. Patterson, John L. Hennessy220 solutions


Fundamentals of Database Systems
7th Edition•ISBN: 9780133970777 (1 more)Ramez Elmasri, Shamkant B. Navathe687 solutions

Introduction to Algorithms
3rd Edition•ISBN: 9780262033848 (2 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen726 solutions
More related questions
1/2
1/3