Skip to content

Commit 576477e

Browse files
committed
Add new file
1 parent af3842f commit 576477e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Diff for: card.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
##This script takes in a sequence and determines what kind of credit card it belongs to.
3+
#Amex cards begin with 34 or 37 and contain 15 digits
4+
#Discover cards begin with 6011, 16 digits
5+
#Mastercard begins with 51/52/53/54/55, 16 digits
6+
#Visa begins with 4, 13 or 16 digits
7+
8+
def get_issuer(number):
9+
card = str(number)
10+
nums = len(card)
11+
12+
if card[:2] in ("34", "37") and nums == 15:
13+
return "AMEX"
14+
elif card[:4] == "6011" and nums == 16:
15+
return "Discover"
16+
elif 51 <= int(card[:2]) <= 55 and nums == 16:
17+
return "Mastercard"
18+
elif card[0] == "4" and nums in (13, 16):
19+
return "VISA"
20+
return "Unknown"
21+
22+
get_issuer(4111111111111111)
23+
24+
#First attempt didnt pass all test cases.
25+
# def get_issuer(number):
26+
# string_num = str(number)
27+
# if len(string_num) == 15:
28+
# print "AMEX"
29+
#
30+
# elif string_num[:4] == 6011:
31+
# print "Discover"
32+
#
33+
# elif string_num[:2] in range(50, 56):
34+
# print "Mastercard"
35+
#
36+
# elif string_num[0] == 4: #and len(string_num) == 16:
37+
# print "VISA"

0 commit comments

Comments
 (0)