Last active
January 22, 2021 10:51
-
-
Save MoorthySuresh/a0827e997c713022244733f4b036aae4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Luhn algorithm | |
#Credit_Card=input("Enter your credit card number: ") | |
Credit_Card="38520000023237" | |
rCredit_Card=Credit_Card[::-1]#reversing the string | |
sCredit_Card=rCredit_Card.strip()#removing spaces before and after a string, if any | |
#print(cn) | |
total=0 | |
for index, value in enumerate (sCredit_Card): | |
if index%2!=0: #extracting even position of digits from left to right. | |
x=int(value)*2 #doubling the even position of digits from left to right | |
if x>9: # addition of digits, if the valus is more than 9 | |
x=x-9 | |
total=total+x | |
#print(total) | |
else: | |
x=int(value) #extracting odd position of digits from left to right. | |
total=total+x | |
total=total | |
#print(total) | |
if total%10==0: | |
if ((len(Credit_Card)==15) and (Credit_Card[:2]=="34" or Credit_Card[:2]=="37")): | |
print("Your American Express card is valid") | |
elif ((len(Credit_Card)==16) and ((Credit_Card[:2]=="51") or (Credit_Card[:2]== "52") or (Credit_Card[:2]== "53") or (Credit_Card[:2]=="54") or (Credit_Card[:2]=="55"))): | |
print("Your Master card is valid") | |
elif ((len(Credit_Card)==16) and (Credit_Card[0:1]=="4")): | |
print("Your Visa card is valid") | |
else: | |
print("Your Card is valid, but check your card provider") | |
else: | |
print("This is not a valid card") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment