Python program that checks if a given number is odd or even:
number = int(input("Enter a number: "))
if number % 2 == 0:
print("The number is even")
else:
print("The number is odd")
The program prompts the user to enter a number using the input() function, and stores the value in the variable “number”. It then uses an if-else statement to check if the remainder of dividing the number by 2 is equal to 0. If the remainder is 0, the number is even. Else, the number is odd.
Another way to check if a number is odd or even is by using bitwise operator:
number = int(input("Enter a number: "))
if number & 1:
print("The number is odd")
else:
print("The number is even")
Here, we use the bitwise operator “&” to check the least significant bit of the number, if it is 1 then the number is odd otherwise the number is even.
Both the methods will give you the same output which is whether the number is odd or even. You can use any method that suits your need or preference.