DEV Community

Srikumaran
Srikumaran

Posted on Edited on

Today i am using python to create a "credit card validator program "

  • this project checks the whether of a credit card number is valid using Luhn algorithm. used technoligies
  1. python
  2. vs code
card = input("Enter card number: ")

card = card.replace(" ", "")

if not card.isdigit():
    print("Invalid card number")
else:
    digits = [int(i) for i in card]

    total = 0
    reverse = digits[::-1]

    for i in range(len(reverse)):
        num = reverse[i]

        if i % 2 == 1:
            num = num * 2

            if num > 9:
                num = num - 9

        total += num

    if total % 10 == 0 and 13 <= len(card) <= 19:
        print("Valid card number")
    else:
        print("Invalid card number")
Enter fullscreen mode Exit fullscreen mode

`

Top comments (0)