Created
September 12, 2017 12:36
-
-
Save jettero/7fc0d911bb8a1e7675820dcdfbd9201c to your computer and use it in GitHub Desktop.
This is 9.
This file contains hidden or 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
#!/usr/bin/env python | |
# coding: UTF-8 | |
import argparse | |
def nine(x): | |
retval = x # <--- the given integer | |
# side note: recursion can always be converted to a loop | |
# particularly tail recursion like this would have been | |
while retval > 10: | |
# the sum of all the digits | |
digit_total = sum([ int(i) for i in str(retval) ]) | |
# subtract the sum of the digits of the current return value | |
retval -= digit_total | |
return retval # <--- this is 9 | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description="this is 9") | |
parser.add_argument("some_number", type=int) | |
args = parser.parse_args() | |
if int( args.some_number ) < 10: | |
print "given number must be a positive integer greater than 9" | |
exit(1) | |
print nine(args.some_number) |
Author
jettero
commented
Jun 30, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment