Program to print the odd number in the given range using Python

by | Mar 31, 2021 | Python Programs

Introduction

In this section of python programming, we will print the odd numbers in the range provided by the user. We have already seen in the previous sections to find the odd numbers in the list.

Expression: num % 2 != 0

Program to print the odd number in the given range 

 

Program

negative_list = []

n = int(input("Enter the lower bound of the list "))

m = int(input("Enter the upper bound of the list "))

# Using for loop

new_list = []

for i in range(n, m+1):

    if i % 2!= 0:

        new_list.append(i)

print("Odd numbers in the range {0} to {1} is {2}".format(n,m, new_list))

Output

Program to print the odd number in the given range Output

Explanation

In the above code we have used “for loop” to find the odd numbers in the range n to m + 1 (to include upper bound). The “if condition” will check whether the number is odd or not. If the number is odd, it is appended to the list. When all the values get traversed in the range, the odd values are printed on the screen.

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.