Python program to print all odd numbers in a range

In this article, we will learn to print all the odd numbers in a range using the python program.

We will use for loop to do that.

Input:

Start = 4

End = 10

Output: 

[5, 7, 8]


Explanation

  1. First, we will take input from users for starting and ending numbers.
  2. Then we will iterate for loop from start to end+1.
  3. After that, we will append all the odd numbers to result in a list.
  4. Then we print the result.


Program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# take input from the user
Start = int(input("Enter starting number: "))
End = int(input("Enter ending number: "))

result = []

for ele in range(Start,End+1):
    if ele%2!=0:
       result.append(ele)
       
# print result
print(result)
    


Output

Enter starting number: 4
Enter ending number: 10
[5, 7, 9]
Next Post Previous Post
No Comment
Add Comment
comment url