Advertisement
Guest User

Untitled

a guest
Mar 27th, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. import sys
  2.  
  3. def add_number(x):
  4.   # double every other
  5.   d = []
  6.   for o, n in enumerate(x):
  7.     if (o % 2):
  8.       d.append(int(n)*2)
  9.     else:
  10.       d.append(int(n))
  11.   # sum the numbers
  12.   total = 0
  13.   for n in d:
  14.     for c in str(n):
  15.       total += int(c)
  16.   return total
  17.  
  18. def add_check(x):
  19.   print "{} check: {}".format(x, add_number(x) * 9 % 10)
  20.  
  21. def verify_check(x):
  22.   total = add_number(x[:-1])
  23.   if (total * 9 % 10) == int(x[-1]):
  24.     return True
  25.   return False
  26.  
  27. if __name__ == '__main__':
  28.   if len(sys.argv) != 2:
  29.     add_check(sys.argv[2])
  30.   else:
  31.     print verify_check(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement