Python program to check if a number is odd or even
By Lenin Mishra
A number is divisible by 2, it is even, else odd.
You can use the modulus operator %
to compute the remainder.
If the remainder is not zero, the number is odd.
Example 1
Code
num = 12
if num%2 == 0:
print("It is even")
else:
print("It is odd")
Output
It is even
Example 2 - Asking for user input
Code
num = int(input("Enter a number ==> "))
if num%2 == 0:
print("It is even")
else:
print("It is odd")
Output
Enter a number ==> 9
It is odd
The above code uses the input() function to ask for user input.