Latest posts

10/recent/ticker-posts

Palindrome Number Program in Python | check whether an number is a Palindrome number or not in Python

Palindrome Number program in Python



I have created a Program to check an Number is Palindrome Number or Not !

So we need to know that what is Palindrome Number.

Suppose, 121 is a Number, in that when we take the reverse of this number, It again gives result as 121. So this type of Numbers are called as Palindrome Number.
Palindrome number : When the reverse of an number is returns the result as same as actual number, then those numbers are called as Palindrome Numbers.

Ex,

Example of Palindrome Number


Given example shows the actual meaning of Palindrome Number.

Starting of Program in Python :


Firstly we need to take a number from user. for that we used,

    num = int(input("Enter a Number : "))

we created a variable with name 'num' and in that we stored those number which is entered by user.

To take the input from user, we used input() function.

After that, we created a variable 'temp' to store our actual number in a temporary variable.


    temp = num
       

we created one another variable 'reverse' to store the reverse of our original number

After that, we used a while-loop to iterate a statement until the given condition in not breaks.


    while(num > 0):                                
        digit = num%10             # we created another variable digit for modulation    
        reverse = reverse * 10 + digit  # logic of reverse number           
        num = num//10               


So in this while loop, we passed a condition, num > 0 , because of this, our while loop will iterates until our 'num' becomes zero.

After that, we have entered our logic of Palindrome number in while loop.
You can whatch the Palindrome Numbers logic in our youtubes video (Link is given in bottom of the post ).

After that, we used if-else statment to check our number is an Palindrome Number or Not !


    if(temp == reverse):                            
        print(f"{temp} is a Palindrome !")          
        print("")
        print("")
    else:
        print(f"{temp} is not a Palindrome !")
        print("")
        print("")



Output : 


    Enter a Number : 253

    253 is not a Palindrome ! 

    -----------------------------------------------------

    
    Enter a Number : 565

    565 is a Palindrome !



Try yourself : 





Youtube Video : 










Also Visit


Post a Comment

0 Comments