Simple if statement

Write a Python function that takes an integer as input and returns “Even” if the number is even and “Odd” if it’s odd.

Complete Listing 1. Save the completed code as check_even_odd.py and run it to check the supplied assertions.

Listing 1: Starter function and checks for check_even_odd.
def check_even_odd(num: int) -> str:
    raise NotImplementedError("Replace this line with your code.")


# An even number
got = check_even_odd(4)
assert got == "Even", f"4: expected 'Even', got {got!r}"

# An odd number
got = check_even_odd(7)
assert got == "Odd", f"7: expected 'Odd', got {got!r}"

# Zero: even, and easy to get wrong
got = check_even_odd(0)
assert got == "Even", f"0: expected 'Even', got {got!r}"

# A negative odd number, where the remainder can surprise you
got = check_even_odd(-7)
assert got == "Odd", f"-7: expected 'Odd', got {got!r}"

# Your case: which number is most likely to break it?
# got = check_even_odd(___)
# assert got == "___", f"___: expected '___', got {got!r}"
  • assert condition checks a Boolean condition. A true condition produces no output; a false condition raises AssertionError. For example, assert 2 + 3 == 5 passes.
  • a % b returns the remainder after division by nonzero b. For example, 7 % 3 is 1, and 12 % 4 is 0.