Palindrome Program in Python Without using String Functions

Previously we have developed palindrome numbers in python and palindrome strings in python. Now in this post, we will develop a palindrome program in python without using string functions. We will check the given number is a palindrome number or not. Also, We will check the given string is a palindrome string or not.

Palindrome Number in Python Without using String Functions

Palindrome number:- If the Reverse of a number is equal to the same number then the number is called a palindrome number.

Example of palindrome number:-
54345 = 54345 So, 54345 is a palindrome number.
79846 != 64897 So, 79846 is not a palindrome number.

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

# Palindrome number in python without using string functions

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

# check number is palindrome or not
if(num == num[::-1]):
   print(num,'is a Palindrome')
else:
   print(num,'is not a Palindrome')

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

Enter the number: 5665
5665 is a Palindrome

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

Enter the number: 19854
19854 is not a Palindrome

Palindrome Number Program in Python Without using String Functions

We can also take the help of a function to check the palindrome number in python. A function is a block of code that performs a specific task.

# Palindrome number in python using for loop

def isPalindrome(num):  #user-defined function
   if(num == num[::-1]):
      return True

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

# calling function and display result
reverse = isPalindrome(num)
if reverse:
   print(num,'is a Palindrome')
else:
   print(num,'is not a Palindrome')

Output:-

Enter the number: 2356532
2356532 is a Palindrome

Palindrome Program in Python Without using String Functions

Palindrome string:- If the reverse of the string is the same string then the string is called palindrome string.

Some examples of palindromic words are civic, radar, redivider, noon, level, rotor, racecar, redder, kayak, reviver, madam, and refer.

# Palindrome program in python using for loop

# take inputs 
string = input('Enter the string: ')

# check string is palindrome or not
if(string == string[::-1]):
   print(string,'is a Palindrome')
else:
   print(string,'is not a Palindrome')

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

Enter the string: noon
noon is a Palindrome

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

Enter the string: Know Program
Know Program is not a Palindrome

Palindrome String Program in Python Without using String Function

We can also take the help of a function to check the palindrome program in python. A function is a block of code that performs a specific task.

# Palindrome program in python using for loop

def isPalindrome(s):  #user-defined function
   if(s == s[::-1]):
      return True

# take inputs 
string = input('Enter the string: ')

# calling function and display result
reverse = isPalindrome(string)
if reverse:
   print(string,'is a Palindrome')
else:
   print(string,'is not a Palindrome')

Output:-

Enter the string: level
level is a Palindrome

Leave a Comment

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