Skip to content
ExamSpine

Lesson 4.3 · Write it

Is even

A functionPython or Java7 tests, 4 of them hidden

On a phone? Put the lines in order instead

Write a function that returns whether a whole number is even.

  1. n is a whole number that can be negative, zero, or positive.
  2. Return True (Python) or true (Java) if n is divisible by 2 with no remainder, False or false otherwise.
  3. Zero is even.

Only the value your function returns is checked.

def is_even(n: int) -> bool

Examples

Your function is tested on 7 cases: the 3 examples below, and 4 hidden ones that check the rules above.

  • is_even(4) should return True: a positive even number (rule 2)
  • is_even(7) should return False: an odd number (rule 2)
  • is_even(0) should return True: zero is even (rule 3)

public static boolean isEven(int n)

Checking whether Java answers can run here.

Examples

Your function is tested on 7 cases: the 3 examples below, and 4 hidden ones that check the rules above.

  • isEven(4) should return true: a positive even number (rule 2)
  • isEven(7) should return false: an odd number (rule 2)
  • isEven(0) should return true: zero is even (rule 3)
solution.pySolution.java