Apr-16-2020, 09:29 PM
(This post was last modified: Apr-16-2020, 09:46 PM by deanhystad.)
There is no reason to test every value. If the result must be divisible for all numbers 1 through 9, the number will be divisible by 9. There is no reason to test 17 or 33 or 121.
def find_number(first, last): """Find first number that is divisible by all numbers in range first..last""" num = last while True: for divisor in range(first, last): if num % divisor != 0: # Failed test. Try next num num += last break # break out of for loop else: # Gets called if for loop reaches end print(num) break; # Break out of while loop find_number(5, 13)