Reverse Digits Same or Not Program in Python


A five-digit number is entered through the keyboard. Write a program to obtain the reversed number and to determine whether the original and reversed numbers are equal or not.

This program is checking whether the input number is a palindrome or not. It does this by first storing the input number into a variable 'a', then initializing a variable 'sum' to 0. It then enters a while loop that continues until the input number is greater than 0. Within the while loop, the program first calculates the remainder when the input number is divided by 10 and assigns it to the variable 'rem'. It then multiplies the current value of 'sum' by 10 and adds the value of 'rem' to it, updating the value of 'sum'. The input number is then divided by 10 using floor division and reassigned to the variable 'num'. This process continues until the while loop exits.

After the while loop, the program then compares the original input number 'a' with the reversed number 'sum'. If they are equal, it prints "Eqaul.." which means the input number is a palindrome number, otherwise it prints "Not Equal.." which means the input number is not a palindrome number


Source Code

num = int(input("Enter the Number :"))
a=num
sum=0
while(num>0):
	rem=num%10
	sum=(sum*10)+rem
	num=num//10
if(a==sum):
	print("Eqaul..")
else:
	print("Not Eqaul..")

Output

Enter the Number :12321
Eqaul..

Enter the Number :34256
Not Eqaul..


Example Programs