Create a function is_even(n) that takes an integer n as input and returns True if the number is even, and False otherwise.

1 answer

Here's a simple function in Python that checks if a number is even:

def is_even(n):
    return n % 2 == 0

Explanation:

  • The function is_even takes an integer n as input.
  • It uses the modulus operator % to check the remainder of n when divided by 2.
  • If the remainder is 0, it returns True (indicating that n is even); otherwise, it returns False.

Example Usage:

print(is_even(4))  # Outputs: True
print(is_even(7))  # Outputs: False