Given starting and end points, write a Python program to print all odd numbers in that given range.
Example:
Input: start = 4, end = 15 Output: 5, 7, 9, 11, 13, 15 Input: start = 3, end = 11 Output: 3, 5, 7, 9, 11
Example #1: Print all odd numbers from given list using for loop
Define start and end limit of range. Iterate from start till the range in the list using for loop and check if num % 2 != 0. If the condition satisfies, then only print the number.
# Python program to print odd Numbers in given range start, end = 4, 19 # iterating each number in list for num in range(start, end + 1): # checking condition if num % 2 != 0: print(num, end = " ") |
Output:
5 7 9 11 13 15 17 19
Example #2: Taking range limit from user input
# Python program to print Even Numbers in given range start = int(input("Enter the start of range: ")) end = int(input("Enter the end of range: ")) # iterating each number in list for num in range(start, end + 1): # checking condition if num % 2 != 0: print(num, end = " ") |
Output:
Enter the start of range: 3 Enter the end of range: 11 3 5 7 9 11
Example #3: Taking range limit from user input
# Python program to print Even Numbers in given range start = int(input("Enter the start of range: ")) end = int(input("Enter the end of range: ")) #create a list that contains only Even numbers in given range even_list = range(start, end + 1)[start%2::2] for num in even_list: print(num, end = " ") |
Output:
Enter the start of range: 3 Enter the end of range: 11 3 5 7 9 11
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Python program to print all negative numbers in a range
- Python program to print all even numbers in a range
- Python program to print all positive numbers in a range
- C++ program to print all Even and Odd numbers from 1 to N
- Python program to print odd numbers in a List
- Find kth smallest number in range [1, n] when all the odd numbers are deleted
- Python Program for Number of elements with odd factors in given range
- Print all numbers in given range having digits in strictly increasing order
- Count Odd and Even numbers in a range from L to R
- Python Program to Print Largest Even and Largest Odd Number in a List
- Python program to print all Prime numbers in an Interval
- Python program to print all Strong numbers in given list
- Python Program for Efficient program to print all prime factors of a given number
- Python program to count Even and Odd numbers in a List
- Python Program to find Sum of Negative, Positive Even and Positive Odd numbers in a List
- Program to print Sum of even and odd elements in an array
- Program to print product of even and odd indexed elements in an Array
- Python program to find the sum of all even and odd digits of an integer list
- Program to print all the numbers divisible by 3 and 5 for a given number
- Program to print all the numbers divisible by 5 or 7 for a given number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : KenMa

