Python Program to Print Odd Numbers Between Two Numbers

Python Program to Print Odd Numbers Between Two Numbers

In this article, we will be solving question based on Iteration and basic mathematical operation with Python. According to the question we have to print all the odd numbers between two numbers.

If you like the article content, then share it in your coding groups so that more people can take advantage of the content. So, without wasting any time let's solve this question.

Question - Write a Python Program to Print Odd Numbers Between Two Numbers

Python Program to Print Odd Numbers Between Two Numbers


Logic and Explanation

Question - Write a Python Program to Print Odd Numbers Between Two Numbers

Python Program to Print Odd Numbers Between Two Numbers - In this program we have to first take the two numbers input from the user between whose we have to print the odd numbers.

n1 = int(input("Enter starting no"))
n2 = int(input("Enter ending no"))


Now the next step is to iterate through all the numbers between n1 and n2 and then check each number for the odd. For this we will check the remainder on dividing the number by 2. If it comes non zero, then the number is an odd number and thus we will print that number in the loop. Here's the code for the same.

for x in range(n1+1,n2):
    if x%2 != 0:
        print(x)


So, I hope you liked the article and you would have found the content of the article useful and helpful for you. Share this article in your coding communities so that more people can take advantage of the content. Also, In case of any doubt feel free to ask in the comments below.

For More Such Python Programs - Click Here

Enjoy Coding!!!


Also Read :-

Extract Phone Number Details Using Python





For any doubts feel free to ask in comments below.
Stay Connected to Us for more such Courses and Projects.

Post a Comment

For any doubts feel free to ask in comments below.
Stay Connected to Us for more such Courses and Projects.

Post a Comment (0)

Previous Post Next Post