Q:

Python | Program to print Palindrome numbers from the given list

0

First few palindrome numbers are 0, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 11 , 22 , 33 , 44 , 55 , 66 , 77 , 88 , 99 , 101 , 111 , 121 , ... and so on.

Input format: Given a number nsize of list then next line contains space separated n numbers.

Logic: We will simply convert the number into string and then using reversed(string) predefined function in python ,we will check whether the reversed string is same as the number or not.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

# Give size of list
n=int(input())

# Give list of numbers having size n
l=list(map(int,input().strip().split(' ')))

print("Palindrome numbers are:")
# check through the list to check 
# number is palindrome or not
for i in l:
    num=str(i)
    if("".join(reversed(num))==num):
        print(i)

Output

Python program to print palindrome number

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now