luhn_ok#

scikitplot.cleanprompt.luhn_ok(digits)[source]#

Return whether digits satisfies the Luhn checksum.

Parameters:
digitsstr

A string of decimal digits, already stripped of separators.

Returns:
bool

True when the Luhn check passes and the length is plausible for a payment card (12 to 19 digits).

Parameters:

digits (str)

Return type:

bool

Notes

Developer notes. Luhn is a transcription-error check, not a validity proof: it rejects roughly 90 percent of random digit runs, which is enough to keep order numbers and long identifiers out of the card category while never rejecting a genuine card.

Examples

>>> luhn_ok("4242424242424242")
True
>>> luhn_ok("4242424242424241")
False