Print Palindrome Numbers in Python-DecodingDevOps

Print Palindrome Numbers in Python

A Palindrome number is a number that remains the same when it is reversed. spacing between the numbers is also allowed. palindromic prime exists when the number which is a palindrome is also a prime for example 191 and 313. palindromes not only includes the numbers but also the words, phrases, and sentences. palindromes are also seen in dates, acoustics and many other modern and classical music pieces. The purpose of using palindromes in your writing, whether it’s words, whole sentences or numbers, is to exercise your brain, working within tight parameters to create something interesting and entertaining.

highest= int(input(" Please Enter the Maximum Value : "))
print("Palindrome Numbers between %d and %d are : " %(1, highest))

for num in range(1, highest+ 1):

    temp = num

    reverse = 0
    
    while(temp > 0):

        Reminder = temp % 10

        reverse = (reverse * 10) + Reminder

        temp = temp //10

    if(num == reverse):

        print("%d " %num, end = '  ')

STEP 1: In this step, we will give an input which is the maximum limit value up to which the palindrome numbers are present.

STEP 2: In this step, using print statement and the given input this program should have all the values within the maximum limit number

STEP 3: In this step, we use the for loop to iterate the loop between the minimum value which is 1 and the maximum limit value which we gave as an input within the for loop.

STEP 4: In this step, we will assign the temp variable to the number and reverse variable to 0.

STEP 5: In this step, we use while loop to check the reverse of the number and iterating over the loop.

STEP 6: In this step, we use the for loop to check whether the number is equal to the reverse of itself. if it is equal print it as a palindrome and print the palindromic numbers within the given range.

OUTPUT:

Please Enter the Maximum Value : 90
Palindrome Numbers between 1 and 90 are : 
1   2   3   4   5   6   7   8   9   11   22   33   44   55   66   77   88

 

Leave a Reply

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