- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

When it is required to find all the numbers that are odd, and are palindromes and lie between a given range of values, and it has been told that recursion can’t be used, then, list comprehension, and ‘%’ operator can be used to achieve the same.

Palindromes are string that are same when they are read in either way- left to right and right to left.

Below is a demonstration for the same −

my_list = [] lower_limit = 5 upper_limit = 189 print("The lower limit is : ") print(lower_limit) print("The upper limit is : ") print(upper_limit) my_list = [x for x in range(lower_limit,upper_limit+1) if x%2!=0 and str(x)==str(x)[::-1]] print("The numbers which are odd and palindromes between " + str(lower_limit) + " and " + str(upper_limit) + " are : ") print(my_list)

The lower limit is : 5 The upper limit is : 189 The numbers which are odd and palindromes between 5 and 189 are : [5, 7, 9, 11, 33, 55, 77, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181]

- An empty list, a lower limit and an upper limit is defined.
- The upper and lower limit are displayed on the console.
- The values between upper and lower limit are iterated over, and checked to see if it is divisible by 2.
- Then, it is converted to a string, and elements from the end of the string and the string are compared.
- This is assigned to a variable.
- This is displayed as output on the console.

- Related Questions & Answers
- Python program to print all odd numbers in a range
- PHP program to find the sum of odd numbers within a given range
- Python Program to Find all Numbers in a Range which are Perfect Squares and Sum of all Digits in the Number is Less than 10
- Program to find bitwise AND of range of numbers in given range in Python
- 8085 program to take all numbers which are in range 3CH and 64H in an array
- Python program to print all even numbers in a range
- Golang Program to Print Odd Numbers Within a Given Range
- C++ program to find numbers with K odd divisors in a given range
- Program to count odd numbers in an interval range using Python
- Golang Program to Find the Numbers which are Divisible by 7 and Multiple of 5 in a Given Range
- Program to find sum of first N odd numbers in Python
- Program to find all contiguously increasing numbers in start end range in Python
- Python - Find the number of prime numbers within a given range of numbers
- Program to find count of numbers having odd number of divisors in given range in C++
- Find kth smallest number in range [1, n] when all the odd numbers are deleted in C++

Advertisements