Created
July 5, 2011 04:58
-
-
Save diofeher/1064270 to your computer and use it in GitHub Desktop.
cc_validation
This file contains 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
def sum_digits(num): | |
""" | |
@param: num number as string | |
""" | |
return sum([int(digit) for digit in num]) | |
def validate(cc_number): | |
""" | |
@param: cc_number credit card number as string | |
""" | |
members = [] | |
for i, digit in enumerate(cc_number): | |
int_digit = int(digit) | |
if i % 2 == 0: | |
doubled = str(int_digit*2) | |
members.append(sum_digits(doubled)) | |
else: | |
members.append(int_digit) | |
return not sum(members) % 10 | |
if __name__ == '__main__': | |
cc = "4417123456789113" | |
print validate(cc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment