Palindrome Number in Python using For Loop

We will develop a program to check palindrome number in python using for loop. It will check if the given number is a palindrome number or not. If the Reverse of a number is equal to the same number then the number is called a palindrome number.

Example of palindrome number:-
393 = 393 So, 393 is a palindrome number.
132 != 231 So, 132 is not a palindrome number.

Palindrome Program in Python using For Loop

We will take integer numbers as a string while declaring the variables. Then, check if the string is equal to the reverse string or not using the if-else statement. Finally, the result will be displayed on the screen.

Program Description:- Write a Python program to check if the number is a palindrome or not

# Palindrome Program in Python using for loop

# take inputs
num = '22'

# check number is palindrome or not
i=0
for i in range(len(num)):
   if num[i]!=num[-1-i]:
      print(num,'is not a Palindrome')
      break
   else:
      print(num,'is a Palindrome')
      break

Output:-

22 is a Palindrome

Palindrome Number in Python using For Loop

In the previous program, inputs are hardcoded in the program but in this program, input will be provided by the user.

Program Description:- Write a program to check if the given number is a palindrome or not in Python

# Palindrome Number in Python using for loop

# take inputs
num = input('Enter the number: ')

# check number is palindrome or not
i=0
for i in range(len(num)):
   if num[i]!=num[-1-i]:
      print(num,'is not a Palindrome')
      break
   else:
      print(num,'is a Palindrome')
      break

Output for the input values test-case-1:-

Enter the number: 55
55 is a Palindrome

Output for the input values test-case-2:-

Enter the number: 846
846 is not a Palindrome

Output for the input values test-case-3:-

Enter the number: 9532359
9532359 is a Palindrome

Leave a Comment

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