write a program to display all odd numbers from N to M in python?
The given task requires writing a Python program that displays all the odd numbers between a given starting number 'N' and an ending number 'M'. The program should prompt the user to enter the values of N and M, and then it should iterate through all the numbers between N and M using a loop. The program should then check whether each number is odd or not, and if it is, the program should print that number. An odd number is a number that is not exactly divisible by 2, which means that the remainder after dividing the number by 2 is 1. The output of the program would be a list of all odd numbers between the given starting and ending numbers.
Here's a Python program that displays all odd numbers between N and M:
N = int(input("Enter the starting number: ")) M = int(input("Enter the ending number: ")) for i in range(N, M+1): if i % 2 != 0: print(i)
In this program, the user is prompted to enter the starting and ending numbers. The program uses a for loop to iterate through all the numbers between N and M. The if statement inside the loop checks whether the number is odd or not by using the modulus operator %. If the number is odd (i.e., the remainder after dividing by 2 is not 0), the number is printed. The output of the program would be a list of all odd numbers between the given starting and ending numbers.