diff --git a/Programs/P80_checking_validation_of_credit_card.py b/Programs/P80_checking_validation_of_credit_card.py new file mode 100644 index 0000000..ce43cc4 --- /dev/null +++ b/Programs/P80_checking_validation_of_credit_card.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +"""Checking_validation_of_Credit_card.ipynb + +Automatically generated by Colaboratory. + +Original file is located at + https://colab.research.google.com/drive/1i7AszLLJi-Mrw_iWR10w2F7icdopWFMf +""" + +def validity_check(num): # this function adds every digit of the card number to a list and, + validlist=[] + for i in num: + validlist.append(int(i)) + for i in range(0,len(num),2): # applying Luhn Algorithm to check whether resulting sum is divisible by ten + validlist[i] = validlist[i] * 2 + if validlist[i] >= 10: + validlist[i] = (validlist[i]//10 + validlist[i]%10) + + if sum(validlist)% 10 == 0: + print("This is a VALID CARD!") + + else: + print('INVALID CARD NUMBER') + +def card_number(): # accepts card number as a string + + n ='' + while True: + try: + n = input('Enter your 16 digit credit card number : ') + + if not (len(n) == 16) or not type(int(n) == int) : + raise Exception + + except Exception: + print('That is not a valid credit card number. \nMake sure you are entering digits not characters and all the 16 digits.') + continue + + else: + break + + + return n + +def goagain(): + return input('Do you want to check again? (Yes/No) : ').lower()[0] == 'y' + +def main(): + + while True: + + num = card_number() + validity_check(num) + + + if not goagain(): + break + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/README.md b/README.md index c79a6c5..959ae9e 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ Pune, Maharashtra, India.
2. [Hangman](https://github.com/OmkarPathak/Python-Programs/blob/master/Programs/P37_HangmanGame.py) 3. [Rock Paper Scissor](https://github.com/OmkarPathak/Python-Programs/blob/master/Programs/P49_RockPaperScissors.py) 4. [Tic Tac Toe](https://github.com/OmkarPathak/Python-Programs/blob/master/Programs/P75_TicTacToe.py) +5. Credit card validation checker P80_checking_validation_of_credit_card.py ## OOP