#shorts #pythonforbeginners #creditCardValidatorProject
Welcome To Our channel
In this video, you will learn to make credit card validator project using python. It's part-3.
Part - 1 link: • Credit Card Validator | Python Project | P...
Part - 2 link:
*************************** code code code *****************************
making a credit card algorithm
part 1
def get_card():
while True:
card = int(input("Enter Card: "))
card_len = len(str(card))
if card_len (greater than symbol) 13 and card_len (less than) 16:
print("Card okay for now.")
break
else:
print("card not in valid length")
continue
return card
making object
print(get_card())
part 2
getting the type of card
if first number
4 - visa
5 - master card
37 - american express
6 - discovery card
def card_type(card):
if card[:1] == "4":
return "visa card"
elif card[:1] == "5":
return "master card"
elif card[:2] == "37":
return "american express card"
elif card[:1] == "6":
return "discovery card"
else:
return "unkown card!!!"
part - 3
making our luhn algorithm
rules:
1) It will take 2nd number from second
last element and then double them if
the double is greater than 10, it will sum its
digits.
E.g., 2365, it will take 6 and 2,
and double them. 6*2 - 12 greater than 10 so it
will take 1+2 = 3 instead 12. and
2*2 - 4 less than 10 so it will take 4.
2) sum the numbers got. E.g., we got
3 and 4, their sum = 7.
3) Take rest of the numbers and sum
them. So we were left with 3, and 5,
so sum them. sum = 8.
4) Now sum both the sums = 8 + 7 = 15.
5) check if 15 divisible by 10 if yes
then valid credit card, else not.
def validator(card):
getting length of card
card_len = len(card)
list to store every second
digit from right to left
e.g., 12345, so we store.
4, 2
card_num = []
list to store double of num from
card_num list
double_card_num = []
list to store rest of the num
for 12345, we will store.
5, 3, 1
remain_num = []
store the sum
sum = 0
adding every every second digit from
right to left into card_num varaible
card_num.extend(
this contain every second digit
from right to left. It start
from most right num - 1 to card
length - 2
card[card_len - 2 : :-2]
)
for each number in double_card_num
for i in range(len(card_num)):
appending into double_card_num
double_card_num.append(
int(card_num[i])*2
)
if double_card_num[i]/10 != 0:
ones = double_card_num[i]%10
tens = int(
double_card_num[i]/10
)
double_card_num[i] = ones+tens
sum += double_card_num[i]
***************************** code code code ******************************
So consider Giving a video a like, share it with your friends and Subscribe to our channel too for more videos.
Instagram: / rohitnarwal7988
Python book for beginners and intermediate people: https://www.amazon.com/Python-simple-...
Python book for advance topics: https://www.amazon.com/Advance-Python...