This is a Python Program to find all numbers which are odd and palindromes between a range of numbers without using recursion.
The program takes a range and prints all numbers which are odd and palindromes between the range without using recursion.
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.
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)
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.
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.
- Apply for Programming Internship
- Check Information Technology Books
- Apply for Python Internship
- Practice Programming MCQs
- Check Python Books