Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
check integer divisible by 3 using string conversion
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
# Copyright © 2013 KuoE0 <>
# Distributed under terms of the MIT license.
def add_digits(x):
return sum([int(d) for d in str(x)])
def divisible_3(x):
while x >= 10:
x = add_digits(x)
return x in [0, 3, 6, 9]
if __name__ == "__main__":
import sys
for i in range(int(sys.argv[1])):
print i, divisible_3(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.