forked from technojam/Hacktoberfest-2020-Baby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
card.py
34 lines (33 loc) · 1.24 KB
/
card.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def luhn(card_number):
def digits_of(n):
return [int(d) for d in str(n)]
digits = digits_of(card_number)
print(digits)
odd_digits = digits[-1::-2]
print(odd_digits)
even_digits = digits[-2::-2]
print(even_digits)
checksum = 0
checksum += sum(odd_digits)
print(checksum)
print("_________________________________________________________________________________")
for d in even_digits:
checksum += sum(digits_of(d*2))
print(d)
print("_________________________________________________________________________________")
print(digits_of(d))
print("_________________________________________________________________________________")
print(digits_of(d * 2))
print("_________________________________________________________________________________")
print(sum(digits_of(d)))
print("_________________________________________________________________________________")
print(sum(digits_of(d*2)))
print("_________________________________________________________________________________")
print(checksum)
print(checksum%10)
return (checksum % 10)
#A little code to test it out on a number
if (luhn("8830723086640451")):
print("INVALID")
else:
print("VALID")