-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATM_validity_checker.py
More file actions
39 lines (30 loc) · 1.1 KB
/
ATM_validity_checker.py
File metadata and controls
39 lines (30 loc) · 1.1 KB
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
35
36
37
38
39
card_digits = ""
state = False
def ATM_validity_checker():
'''This uses Lunh's algorithm'''
global card_digits, state
while state is False:
try:
card_digits = input("Enter all the PAN digits located on the front of your ATM card: ")
if card_digits.isdigit() is True and len(card_digits) >= 15:
state = True
card_digits = [int(item) for item in card_digits]
lunh_step1a = list(map(lambda digit: (digit * 2) , card_digits[-2::-2]))
lunh_step1b = [str(digit) for digit in lunh_step1a]
lunh_step1ca = [list(digit) for digit in lunh_step1b]
lunh_step1_result = sum([int(digit) for digit_string in lunh_step1ca for digit in digit_string])
card_digits2 = [card_digits.remove(digit) for digit in card_digits[-2::-2]]
lunh_step2 = sum(card_digits)
lunh_ans = lunh_step1_result + lunh_step2
if lunh_ans % 10 == 0:
print("Valid")
else:
state = False
print("Invalid")
else:
raise ValueError
except ValueError:
print()
print("Invalid PAN.", "Kindly re-enter your ATM's PAN.", sep = "\n")
print()
ATM_validity_checker()