Skip to content

Commit 701a76c

Browse files
Merge pull request #1 from amlanmohanty1/game1
Game1
2 parents 6039e35 + 634c547 commit 701a76c

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# -*- coding: utf-8 -*-
2+
"""Checking_validation_of_Credit_card.ipynb
3+
4+
Automatically generated by Colaboratory.
5+
6+
Original file is located at
7+
https://colab.research.google.com/drive/1i7AszLLJi-Mrw_iWR10w2F7icdopWFMf
8+
"""
9+
10+
def validity_check(num): # this function adds every digit of the card number to a list and,
11+
validlist=[]
12+
for i in num:
13+
validlist.append(int(i))
14+
for i in range(0,len(num),2): # applying Luhn Algorithm to check whether resulting sum is divisible by ten
15+
validlist[i] = validlist[i] * 2
16+
if validlist[i] >= 10:
17+
validlist[i] = (validlist[i]//10 + validlist[i]%10)
18+
19+
if sum(validlist)% 10 == 0:
20+
print("This is a VALID CARD!")
21+
22+
else:
23+
print('INVALID CARD NUMBER')
24+
25+
def card_number(): # accepts card number as a string
26+
27+
n =''
28+
while True:
29+
try:
30+
n = input('Enter your 16 digit credit card number : ')
31+
32+
if not (len(n) == 16) or not type(int(n) == int) :
33+
raise Exception
34+
35+
except Exception:
36+
print('That is not a valid credit card number. \nMake sure you are entering digits not characters and all the 16 digits.')
37+
continue
38+
39+
else:
40+
break
41+
42+
43+
return n
44+
45+
def goagain():
46+
return input('Do you want to check again? (Yes/No) : ').lower()[0] == 'y'
47+
48+
def main():
49+
50+
while True:
51+
52+
num = card_number()
53+
validity_check(num)
54+
55+
56+
if not goagain():
57+
break
58+
59+
if __name__ == '__main__':
60+
main()

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Pune, Maharashtra, India.<br />
4646
2. [Hangman](https://github.com/OmkarPathak/Python-Programs/blob/master/Programs/P37_HangmanGame.py)
4747
3. [Rock Paper Scissor](https://github.com/OmkarPathak/Python-Programs/blob/master/Programs/P49_RockPaperScissors.py)
4848
4. [Tic Tac Toe](https://github.com/OmkarPathak/Python-Programs/blob/master/Programs/P75_TicTacToe.py)
49+
5. [Credit card validation checker](https://github.com/OmkarPathak/Python-Programs/blob/master/Programs/P80_checking_validation_of_credit_card.py)
4950

5051
## OOP
5152

0 commit comments

Comments
 (0)