Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # American Express
- # American Express uses 15-digit numbers
- # starts with 34 or 37
- # MasterCard
- # MasterCard uses 16-digit numbers
- # starts with 51, 52, 53, 54, 55
- # Visa
- # Visa uses 13- and 16-digit numbers
- # starts with 4
- # =======================================
- # DEBUGGING NEEDED: problem with input
- # credit card number
- credit = 0
- # input
- inpt = input("Number: ")
- def inptFunc(x):
- '''just a simple function for input automation'''
- try:
- int(x)
- return int(x)
- except ValueError:
- y = input("Number: ")
- inptFunc(y)
- credit = inptFunc(inpt)
- # calculate
- while True:
- credit_str = str(credit)
- count = 0
- temp = 0
- # AmEx
- if len(credit_str) == 15 and credit_str[0] == '3':
- if credit_str[1] == '4' or '7':
- # 2nd to last digits
- length = len(credit_str) - 2
- # (1st step) make str
- temp_str = ""
- for i in credit_str:
- if length >= 0:
- temp = int(credit_str[length]) * 2
- temp_str += str(temp)
- # increment index
- length -= 2
- # (2nd step) add all of 'em
- for i in range(len(str(temp_str))):
- count += int(temp_str[i])
- # other digits
- length = len(credit_str) - 1
- for i in credit_str:
- if length >= 0:
- count += int(credit_str[length])
- length -= 2
- # check and out
- if count % 10 == 0:
- print("AMEX")
- break
- else:
- print("INVALID")
- break
- # MasterCard
- elif len(credit_str) == 16 and credit_str[0] == '5':
- if credit_str[1] == '1' or '2' or '3' or '4' or '5':
- # 2nd to last digits
- length = len(credit_str) - 2
- # (1st step) make str
- temp_str = ""
- for i in credit_str:
- if length >= 0:
- temp = int(credit_str[length]) * 2
- temp_str += str(temp)
- # increment index
- length -= 2
- # (2nd step) add all of 'em
- for i in range(len(str(temp_str))):
- count += int(temp_str[i])
- # other digits
- length = len(credit_str) - 1
- for i in credit_str:
- if length >= 0:
- count += int(credit_str[length])
- length -= 2
- # check and out
- if count % 10 == 0:
- print("MASTERCARD")
- break
- else:
- print("INVALID")
- break
- # COPY-PASTE ramining: in Visa
- # Visa
- elif len(credit_str) == 13 or 16 and credit_str[0] == '4':
- # 2nd to last digits
- length = len(credit_str) - 2
- # (1st step) make str
- temp_str = ""
- for i in credit_str:
- if length >= 0:
- temp = int(credit_str[length]) * 2
- temp_str += str(temp)
- # increment index
- length -= 2
- # (2nd step) add all of 'em
- for i in range(len(str(temp_str))):
- count += int(temp_str[i])
- # other digits
- length = len(credit_str) - 1
- for i in credit_str:
- if length >= 0:
- count += int(credit_str[length])
- length -= 2
- # check and out
- if count % 10 == 0:
- print("VISA")
- break
- else:
- print("INVALID")
- break
- # if no cards matched
- else:
- print("INVALID")
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement