btw if a branch returns then the code that comes after the if-statement is already exclusive and doesn’t need to be inside else and the additional indentation that comes with it
exit like so
otherwise do something else
another thought is that the iteration you’re doing is “any” - if any of these numbers divide this number
several loop concepts have function equivalents, and any is one of them
And yeah I’m already using some silly fancy things.
return not any(x % d == 0 for d in range(2, x))
divisors = range(2, x)
dividesX = lambda d: x % d == 0
return not any(map(dividesX, divisors))
… I’m probably just making things complicated.
but at the same time, simpler, because I’m no longer writing the loop.
Figure out all the potential divisors (range)
Define a test for a single divisor (given a number d, does d divide x?)
Apply the test to each divisor (map)
Check if any passed (any)