forked from course-work/week1
done
This commit is contained in:
parent
fd9a28c43e
commit
54a46068fb
@ -1,60 +1,94 @@
|
|||||||
class CreditCard:
|
class CreditCard:
|
||||||
|
card_types = [
|
||||||
|
('4', 'VISA'),
|
||||||
|
('34', 'AMEX'),
|
||||||
|
('37', 'AMEX'),
|
||||||
|
('51', 'MASTERCARD'),
|
||||||
|
('52', 'MASTERCARD'),
|
||||||
|
('53', 'MASTERCARD'),
|
||||||
|
('54', 'MASTERCARD'),
|
||||||
|
('55', 'MASTERCARD'),
|
||||||
|
('6011', 'DISCOVER'),
|
||||||
|
]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def luna_check(cls, card_number):
|
||||||
|
digits = []
|
||||||
|
for index, digit in enumerate(card_number[::-1]):
|
||||||
|
if index % 2:
|
||||||
|
digits += [int(i) for i in str(int(digit)*2)]
|
||||||
|
else:
|
||||||
|
digits.append(int(digit))
|
||||||
|
|
||||||
|
return not bool(sum(digits) % 10)
|
||||||
|
|
||||||
def __init__(self, card_number):
|
def __init__(self, card_number):
|
||||||
self.card_number = "the card number"
|
self.card_number = card_number
|
||||||
self.card_type = "a string"
|
|
||||||
self.valid = "a boolean"
|
|
||||||
|
|
||||||
#Create and add your method called `determine_card_type` to the CreditCard class here:
|
|
||||||
def determine_card_type(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def card_type(self):
|
||||||
|
for start, type in self.card_types:
|
||||||
|
if self.card_number.startswith(start):
|
||||||
|
return type
|
||||||
|
|
||||||
#Create and add your method called `check_length` to the CreditCard class here:
|
#Create and add your method called `check_length` to the CreditCard class here:
|
||||||
def check_length(self):
|
def check_length(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#Create and add your method called 'validate' to the CreditCard class here:
|
@property
|
||||||
def validate(self):
|
def is_valid(self):
|
||||||
pass
|
return self.luna_check(self.card_number), self.card_type
|
||||||
|
|
||||||
|
#Create and add your method called 'validate' to the CreditCard class here:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# print(CreditCard.luna_check('4485040993287616'))
|
||||||
|
cc = CreditCard('4485040993287616')
|
||||||
|
|
||||||
|
print(cc.is_valid)
|
||||||
|
exit(0)
|
||||||
|
|
||||||
#do not modify assert statements
|
#do not modify assert statements
|
||||||
|
|
||||||
cc = CreditCard('9999999999999999')
|
cc = CreditCard('9999999999999999')
|
||||||
|
|
||||||
assert cc.valid == False, "Credit Card number cannot start with 9"
|
assert cc.is_valid == False, "Credit Card number cannot start with 9"
|
||||||
assert cc.card_type == "INVALID", "99... card type is INVALID"
|
assert cc.card_type == "INVALID", "99... card type is INVALID"
|
||||||
|
|
||||||
cc = CreditCard('4440')
|
cc = CreditCard('4440')
|
||||||
|
|
||||||
assert cc.valid == False, "4440 is too short to be valid"
|
assert cc.is_valid == False, "4440 is too short to be valid"
|
||||||
assert cc.card_type == "INVALID", "4440 card type is INVALID"
|
assert cc.card_type == "INVALID", "4440 card type is INVALID"
|
||||||
|
|
||||||
cc = CreditCard('5515460934365316')
|
cc = CreditCard('5515460934365316')
|
||||||
|
|
||||||
assert cc.valid == True, "Mastercard is Valid"
|
assert cc.is_valid == True, "Mastercard is Valid"
|
||||||
assert cc.card_type == "MASTERCARD", "card_type is MASTERCARD"
|
assert cc.card_type == "MASTERCARD", "card_type is MASTERCARD"
|
||||||
|
|
||||||
cc = CreditCard('6011053711075799')
|
cc = CreditCard('6011053711075799')
|
||||||
|
|
||||||
assert cc.valid == True, "Discover Card is Valid"
|
assert cc.is_valid == True, "Discover Card is Valid"
|
||||||
assert cc.card_type == "DISCOVER", "card_type is DISCOVER"
|
assert cc.card_type == "DISCOVER", "card_type is DISCOVER"
|
||||||
|
|
||||||
cc = CreditCard('379179199857686')
|
cc = CreditCard('379179199857686')
|
||||||
|
|
||||||
assert cc.valid == True, "AMEX is Valid"
|
assert cc.is_valid == True, "AMEX is Valid"
|
||||||
assert cc.card_type == "AMEX", "card_type is AMEX"
|
assert cc.card_type == "AMEX", "card_type is AMEX"
|
||||||
|
|
||||||
cc = CreditCard('4929896355493470')
|
cc = CreditCard('4929896355493470')
|
||||||
|
|
||||||
assert cc.valid == True, "Visa Card is Valid"
|
assert cc.is_valid == True, "Visa Card is Valid"
|
||||||
assert cc.card_type == "VISA", "card_type is VISA"
|
assert cc.card_type == "VISA", "card_type is VISA"
|
||||||
|
|
||||||
cc = CreditCard('4329876355493470')
|
cc = CreditCard('4329876355493470')
|
||||||
|
|
||||||
assert cc.valid == False, "This card does not meet mod10"
|
assert cc.is_valid == False, "This card does not meet mod10"
|
||||||
assert cc.card_type == "INVALID", "card_type is INVALID"
|
assert cc.card_type == "INVALID", "card_type is INVALID"
|
||||||
|
|
||||||
cc = CreditCard('339179199857685')
|
cc = CreditCard('339179199857685')
|
||||||
|
|
||||||
assert cc.valid == False, "Validates mod10, but invalid starting numbers for AMEX"
|
assert cc.is_valid == False, "Validates mod10, but invalid starting numbers for AMEX"
|
||||||
assert cc.card_type == "INVALID", "card_type is INVALID"
|
assert cc.card_type == "INVALID", "card_type is INVALID"
|
Loading…
x
Reference in New Issue
Block a user