Exercise 4: Is It Prime? Stop at the First Divisor — Possible Solution ==================================================================== numbers = [2, 15, 17, 21, 97, 100] for n in numbers: for divisor in range(2, int(n ** 0.5) + 1): if n % divisor == 0: print(f"{n} is not prime ({divisor} x {n // divisor})") break else: print(f"{n} is prime") Example run: 2 is prime 15 is not prime (3 x 5) 17 is prime 21 is not prime (3 x 7) 97 is prime 100 is not prime (2 x 50) WHY THIS WORKS AS AN ANSWER ------------------------------ The break and the else both belong to the INNER for loop. The break ends the divisor search the moment one divisor is found (no need to check the rest), and the outer loop carries on with the next number. The else runs only if the inner loop finished without a break, meaning no divisor was found: the number is prime. For n = 2 the range is empty, so the else runs straight away, which is correct. The program assumes every number is at least 2; 1 would wrongly be reported as prime and would need its own check.