Skip to content

Instantly share code, notes, and snippets.

@MishaelRosenthal
Created November 9, 2022 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MishaelRosenthal/e12615b6ffe6fe5c85446fa5bf1bafba to your computer and use it in GitHub Desktop.
Save MishaelRosenthal/e12615b6ffe6fe5c85446fa5bf1bafba to your computer and use it in GitHub Desktop.
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