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
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 – 1000 Python Programs.

If you wish to look at all Python Programming examples, go to 1000 Python Programs.

Free 30-Day Java Certification Bootcamp is Live. Join Now!

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
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 40s–60s and exploring new directions in your career, I also offer mentoring. Learn more here.