Checking divisibility

Write a Python function that takes two integers as input and returns “Divisible” if the first number is divisible by the second number, and “Not Divisible” otherwise. Treat num2 != 0 as a precondition; division by zero is outside this exercise’s input domain.

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

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


# Divides exactly
got = check_divisibility(12, 4)
assert got == "Divisible", f"12, 4: expected 'Divisible', got {got!r}"

# Leaves a remainder
got = check_divisibility(7, 3)
assert got == "Not Divisible", f"7, 3: expected 'Not Divisible', got {got!r}"

# Zero is divisible by anything
got = check_divisibility(0, 7)
assert got == "Divisible", f"0, 7: expected 'Divisible', got {got!r}"

# A negative first number still divides exactly
got = check_divisibility(-12, 4)
assert got == "Divisible", f"-12, 4: expected 'Divisible', got {got!r}"

# Your case: which pair is most likely to break it?
# got = check_divisibility(___, ___)
# 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.