Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- def add_number(x):
- # double every other
- d = []
- for o, n in enumerate(x):
- if (o % 2):
- d.append(int(n)*2)
- else:
- d.append(int(n))
- # sum the numbers
- total = 0
- for n in d:
- for c in str(n):
- total += int(c)
- return total
- def add_check(x):
- print "{} check: {}".format(x, add_number(x) * 9 % 10)
- def verify_check(x):
- total = add_number(x[:-1])
- if (total * 9 % 10) == int(x[-1]):
- return True
- return False
- if __name__ == '__main__':
- if len(sys.argv) != 2:
- add_check(sys.argv[2])
- else:
- print verify_check(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement