Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How determine if a number is even or odd using Modulo Operator

"""
use % (modulo operator) with 2 and compare the
remainder with zero to return a Boolean.
Even numbers are divisible by 2 anddon’t have a remainder.
"""

num = int(input(">"))

def is_even_modulo(number=num):
	return number % 2 == 0

if is_even_modulo():
    print(f"{num} is an even number")
else:
    print(f"{num} is an odd number")
 
PREVIOUS NEXT
Tagged: #How #determine #number #odd #Modulo #Operator
ADD COMMENT
Topic
Name
2+4 =