Is my credit card valid?

debit-cardsIn this challenge we will use the Luhn Algorithm to check if a debit card or credit card number is a valid card number.

This method is used every time you scan or enter your credit card number (e.g. when paying online) to check if your card number is a valid credit card number. This method can be used to quickly detect credit card numbers that have been mistyped or to detect when someone is trying to enter a fake/made up credit card number. Note that it’s not 100% efficient, so is only used a as a pre-check to deter some invalid card numbers. If this first test pass, other checks more robust checks will be performed for the online transaction to be approved.

The Luhn Algorithm


The Luhn Algorithm consists of 4 key steps:
Luhn-Algorithm

Python Challenge


Write program that will ask the end-user to enter a 16-digit card number.
Your program will then apply the Luhn algorithm to decide and output whether or not this card number is valid.

Valid or Invalid Card Numbers?


Test your program with the following card numbers to find the 2 invalid card numbers:

# Card Card Number Valid or Invalid?
#1 credit-card-1 4137 8947 1175 5904
#2 credit-card-2 6499 8024 5027 3568
#3 credit-card-3 8504 1721 9127 3888
#4 credit-card-4 0043 6687 8348 5480
Share Button