Credit Card Validator Using Luhn algorithm
try:
def isluhn(cardNo):
dig=len(cardNo)
nsum=0
isSecond=False
for x in range(dig-1,-1,-1):
d=ord(cardNo[x])-ord('0')
if isSecond==True:
d*=2
nsum+=d//10
nsum+=d%10
isSecond=not isSecond
if not nsum%10:
return True
return False
card=input("enter card no:")
if (isluhn(card)):
print("This is a valid card")
else:
print("This is not a valid card")
except Exception as e:
print(e)