May-17-2018, 05:30 AM
Hi everyone. I very much new to programming.
I implemented Credit card validation program according to following instructions.
1. Let the input be input.
2. Reverse input.
3a. Multiply all odd positions (i.e. indexes 1, 3, 5, etc.) of input by 2.
3b. If any of these multiplied entries is greater than 9, subtract 9.
4. Sum all of the entries of input, store as sum.
5. If sum (mod 10) is equal to 0, the credit card number is valid.
code
Thank you
I implemented Credit card validation program according to following instructions.
1. Let the input be input.
2. Reverse input.
3a. Multiply all odd positions (i.e. indexes 1, 3, 5, etc.) of input by 2.
3b. If any of these multiplied entries is greater than 9, subtract 9.
4. Sum all of the entries of input, store as sum.
5. If sum (mod 10) is equal to 0, the credit card number is valid.
code
# credit card validation - Luhn Formula card_number = list(reversed(input("enter card number: "))) status = False temp1 = [] temp2 = [] sum = 0 for i in card_number: if card_number.index(i) % 2 != 0: temp1.append(int(i) * 2) else: temp1.append(int(i)) for e in temp1: if e > 9: temp2.append(e - 9) else: temp2.append(e) for f in temp2: sum += f if sum % 10 == 0: status = True print("card is VALID") else: print("card is INVALID")code sometimes works and sometimes not. is there a problem with my code.
Thank you