Pure Programmer
Blue Matrix


Cluster Map

Project: Credit Card Validator

The [[Luhn Algorithm]] is a simple checksum algorithm that is used to verify that credit card numbers are correctly entered. Using this algorithm we can easily catch most single digit errors and simple transpositions.

Write a function to verify that the last digit of a credit card is the one expected when computing a checksum digit using the Luhn Algorithm. The function should take a credit card number as a string of 16 digits (no spaces) and return true or false if the last digit matches the computed checksum. Test the program with your own credit card numbers or the samples below.

Output
$ python3 CreditCardValidator.py Good Test Cases 4321123456789019 is True 5432123456789020 is True 65432101234567896 is True Bad Test Cases 4321123456798019 is False 4432123456789020 is False 65431201234567896 is False

Solution