I was trying to implement the Luhn Formula in Python. Here is my code:
import sys
def luhn_check(number):
if number.isdigit():
last_digit = int(
This is the most concise python formula for the Luhn test I have found:
def luhn(n):
r = [int(ch) for ch in str(n)][::-1]
return (sum(r[0::2]) + sum(sum(divmod(d*2,10)) for d in r[1::2])) % 10 == 0
The above function and other Luhn implementations (in different programming languages) are available in https://www.rosettacode.org/wiki/Luhn_test_of_credit_card_numbers .