Skip to content

Added a Python game and updated README.md #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Programs/P80_checking_validation_of_credit_card.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Pune, Maharashtra, India.<br />
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

Expand Down