Created
November 9, 2022 00:16
-
-
Save MishaelRosenthal/e12615b6ffe6fe5c85446fa5bf1bafba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def divisible_by_7(number): | |
number = abs(number) | |
if(number == 7 or number == 0): | |
return True | |
elif(number < 10): | |
return False | |
else: | |
last_digit = number % 10 | |
other_digits = number // 10 | |
return divisible_by_7(other_digits-2*last_digit) | |
# test | |
for i in range(1000): | |
if(not (i%7==0) == divisible_by_7(i)): | |
print("ERROR", i, "is", "divisible by 7" if divisible_by_7(i) else "not divisible by 7") | |
print("done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment