Completethefollowingtwofunctions:#Returnsthereversalofaninteger.#Forexamplereverse(456)returns654defreverse(number):#Returnstrueifnumberisapalindromedefis_palindrome(numb...
Complete the following two functions:
# Returns the reversal of an integer.
# For example reverse(456) returns 654
def reverse(number):
# Returns true if number is a palindrome
def is_palindrome(number):
Use the reverse function to implement the is_palindrome function. A number is a palindrome if its reversal is the same as itself. Write a main function that prompts the user to enter an integer, calls the is_palindrome function (the is_palindrome function will call thereverse function) and then reports whether the integer is a palindrome or not. The template for the question is given below:
# Template starts here
def reverse(number):
# Write code that reverses the number and then returns the reversed number.
def is_palindrome(number):
# Write code that call the reverse function, process the value returned by the reverse function.
# Return True if the number is a palindrome and False otherwise.
def main():
# Write code to prompt the user to enter an integer, calls the is_palindrome function and (depending on the value returned by the is_palindrome function) reports if the number is a palindrome or not.
main() # Call the main function
# Template ends here
Sample Output
Enter a number: 222
The number is a palindrome.
Another Sample Output:
Enter a number: 456
The number is not a palindrome.
必须用上3个def
展开