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 as a pre-check to deter some invalid card numbers. If this first test passes, other more robust checks will be performed for the online transaction to be approved.

The Luhn Algorithm

The Luhn Algorithm consists of 4 key steps:

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


The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 4.3 / 5. Vote count: 31

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!