Python Program to check if the given number is a palindrome number

Here’s an example Python code to check if a given number is a palindrome:

# Define a function to check if a number is a palindrome
def is_palindrome(num):
    # Convert the number to a string and reverse it
    reversed_num_str = str(num)[::-1]
    # Compare the original and reversed strings
    return str(num) == reversed_num_str

# Test the function with some sample numbers
num1 = 12321
num2 = 12345
if is_palindrome(num1):
    print(num1, "is a palindrome.")
    print(num1, "is not a palindrome.")
if is_palindrome(num2):
    print(num2, "is a palindrome.")
    print(num2, "is not a palindrome.")

In this code, we define a function is_palindrome() that takes one argument num and returns True if the number is a palindrome, and False otherwise. To check if the number is a palindrome, we first convert it to a string using the str() function. We then use slicing with a step value of -1 to reverse the string. Finally, we compare the original string and the reversed string to check if they are equal.

In the main program, we test the is_palindrome() function with some sample numbers num1 and num2. We use an if statement to check if each number is a palindrome, and use the print() function to output the result.

When you run this code, it should output:

12321 is a palindrome.
12345 is not a palindrome.

Note that you can replace the sample numbers with any other numbers you want to test the function with.

Related Examples

1. Python Program to Print Hello world!

2. Calculate the multiplication and sum of two numbers

3. Python Program to Find the Square Root

4. Python Program to Calculate the Area of a Triangle

5. Python Program to Solve Quadratic Equation

6. Python Program to Swap Two Variables

7. Python Program to Generate a Random Number

8. Return the count of a given substring from a string

9. Print the following pattern

10. Python Program to print multiplication table form 1 to 10

11. Print downward Half-Pyramid Pattern with Star (asterisk)

12. Python Program to Convert Kilometers to Miles

13. Python Program to Check if a Number is Positive, Negative or 0

14. Python Program to Find the Sum of Natural Numbers

15. Print the sum of the current number and the previous number in Python

Leave a Reply

Your email address will not be published. Required fields are marked *

Wordpress Social Share Plugin powered by Ultimatelysocial
Wordpress Social Share Plugin powered by Ultimatelysocial