- this project checks the whether of a credit card number is valid using Luhn algorithm. used technoligies
- python
- 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")
`
Top comments (0)