Search with a post-test loop
Implement first_multiple_after with while True and break. Starting from start, increment the candidate before testing it. Stop at the first larger integer divisible by divisor. Because the test follows the increment, the loop body always runs at least once.
Both inputs are integers. A negative divisor is allowed. Preserve the supplied ValueError for a zero divisor; division by zero is undefined.
Complete the supplied function in Listing 1. Keep its signature and use the checks below it.
def first_multiple_after(start: int, divisor: int) -> int:
if divisor == 0:
raise ValueError("divisor must not be zero")
candidate = start
while True:
# Increment candidate, then break when it is divisible by divisor.
pass
return candidate
assert first_multiple_after(10, 4) == 12
assert first_multiple_after(12, 4) == 16
assert first_multiple_after(-3, 5) == 0
TipHint
while True repeats until a break exits the loop. % gives a remainder; 12 % 4 is 0. A ValueError reports an invalid argument value.
assert condition stops a failed check with an AssertionError.