Contents
Python Program to Check if Number is Odd
To check if given number is odd or not in Python, we can divide the given number by 2 and find the remainder. If the remainder is equal to one, then the given number is odd, or else not.
If n
is given number, then the boolean condition to check if n
is odd is
n % 2 == 1
Example
In the following program, we take an integer value in n
, and check if this number is odd or not.
Python Program
n = 13
if ( n % 2 == 1 ) :
print(f'{n} is odd number.')
else :
print(f'{n} is not odd number.')
Run Summary
In this tutorial of Python Examples, we learned how to check if a given number is an odd number or not.
Related Tutorials
- How to Get Number of Elements in Pandas DataFrame?
- How to Get Number of Axes in Pandas DataFrame?
- Python – Check if Number is Armstrong
- Python – Largest of Three Numbers
- Python – Sum of First N Natural Numbers
- Python – Sum of Two Numbers
- Python Program to Add Two Numbers
- How to Swap Two Numbers in Python?
- Python – Factorial of a Number
- Numpy sqrt() – Find Square Root of Numbers