Python Program to Find All Odd Palindrome Numbers in a Range without using Recursion

This is a Python Program to find all numbers which are odd and palindromes between a range of numbers without using recursion.

Problem Description

The program takes a range and prints all numbers which are odd and palindromes between the range without using recursion.

Problem Solution

1. Take a upper limit and lower limit from the user.
2. Using list comprehension, store all the numbers in the list that are odd and palindromes.
3. Print the list.
4. Exit.

Program/Source Code

Here is source code of the Python Program to find all numbers which are odd and palindromes between a range of numbers without using recursion. The program output is also shown below.

a=[]
l=int(input("Enter lower limit: "))
u=int(input("Enter upper limit: "))
a=[x for x in range(l,u+1) if x%2!=0 and str(x)==str(x)[::-1]]
print("The numbers are: ",a)
Program Explanation

1. User must enter a upper and lower limit.
2. Using list comprehension, the numbers which are odd(determined using the modulus operator) and that are palindromes(determined using string slicing) are stored into a list.
3. The list is printed.

advertisement
advertisement
Runtime Test Cases
 
Case 1:
Enter lower limit: 100
Enter upper limit: 150
The numbers are:  [101, 111, 121, 131, 141]
 
Case 2:
Enter lower limit: 300
Enter upper limit: 400
The numbers are:  [303, 313, 323, 333, 343, 353, 363, 373, 383, 393]

Sanfoundry Global Education & Learning Series – Python Programs.

To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.

Note: Join free Sanfoundry classes at Telegram or Youtube

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.