Computer >> Computer tutorials >  >> Programming >> Python

How to Check if a Number is Odd or Even using Python?


Python's modulo (%) operator (also called remainder operator) is useful to determine if a number is odd or even. We obtain remainder of division of a number by 2. If it is 0 , it is even otherwise it is odd

no=int(input('enter number'))
if no%2==0:
    print ('{} is even'.format(no))
else:
    print ('{} is odd'.format(no))

The output

enter number25
25 is odd

enter number40
40 is even