palindrome number in python with algorithm


palindrome number in python with algorithm

Q) : Implement python script to check given number is palindrome or not .

Aim: To check given number is palindrome or not
Algorithm : 
step 1: Start
step 2: Declare the variable n and read n
step 3: Assign n = k
step 4: Initialise r = 0 
step 5: In while loop  perform 
           d = n % 10
           r = r * 10 + d
           n = math . floor(n / 10)
step 6: check the condition r == k
step 7: If the condition is true print that given number is palindrome
step 8: Otherwise print the given number is not palindrome
step 9: end
Source Code: 
import math
n = int(input('enter the number :'))
k = n
r = 0 
while n > 0:
    d =n % 10
    r = r * 10 + d
    n = math.floor(n/10)
if r == k:
print('given number is palindrom ')
else:
print('given number is not palindrome')
input:
enter the number:1212
Output :
enter the number :1212
given number is not palindrome

Process finished with exit code 0
input:
enter the number:212
OutPut:
enter the number :212
given number is  palindrome
Process finished with exit code 0
palindrome number in python with algorithm

Have any Question or Comment?

Leave a Reply

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

Categories