This commit is contained in:
William Mantly 2023-09-29 01:55:38 -04:00
parent 54a46068fb
commit 21366bead3
2 changed files with 33 additions and 29 deletions

View File

@ -21,7 +21,7 @@ def matrix_sum(matrix):
return row_sum, col_sum return row_sum, col_sum
def sort_row(matrix): def matrix_sort_row(matrix):
row_sum, col_sum = matrix_sum(matrix) row_sum, col_sum = matrix_sum(matrix)
out = [] out = []
@ -30,7 +30,7 @@ def sort_row(matrix):
return out; return out;
def sort_col(matrix): def matrix_sort_col(matrix):
row_sum, col_sum = matrix_sum(matrix) row_sum, col_sum = matrix_sum(matrix)
out = [] out = []
places = sorted( [i for i in enumerate(col_sum)], key=lambda x:x[1]) places = sorted( [i for i in enumerate(col_sum)], key=lambda x:x[1])

View File

@ -1,14 +1,15 @@
class CreditCard: class CreditCard:
card_types = [ card_types = [
('4', 'VISA'), # (starts with digits, card type, card length)
('34', 'AMEX'), ('4', 'VISA', 16),
('37', 'AMEX'), ('34', 'AMEX', 15),
('51', 'MASTERCARD'), ('37', 'AMEX', 15),
('52', 'MASTERCARD'), ('51', 'MASTERCARD', 16),
('53', 'MASTERCARD'), ('52', 'MASTERCARD', 16),
('54', 'MASTERCARD'), ('53', 'MASTERCARD', 16),
('55', 'MASTERCARD'), ('54', 'MASTERCARD', 16),
('6011', 'DISCOVER'), ('55', 'MASTERCARD', 16),
('6011', 'DISCOVER', 16),
] ]
@classmethod @classmethod
@ -23,21 +24,24 @@ class CreditCard:
return not bool(sum(digits) % 10) return not bool(sum(digits) % 10)
def __init__(self, card_number): def __init__(self, card_number):
self.card_number = card_number self.card_number = card_number
self.is_valid, self.card_type = self.__is_valid() or (False, 'INVALID')
@property def __card_type(self):
def card_type(self): for start, type, length in self.card_types:
for start, type in self.card_types:
if self.card_number.startswith(start): if self.card_number.startswith(start):
return type
#Create and add your method called `check_length` to the CreditCard class here:
def check_length(self):
pass
@property return type, length
def is_valid(self):
return self.luna_check(self.card_number), self.card_type def __is_valid(self):
card_type = self.__card_type()
if card_type:
length = len(self.card_number) == card_type[1]
luna = self.luna_check(self.card_number)
if length and luna:
return True, card_type[0]
#Create and add your method called 'validate' to the CreditCard class here: #Create and add your method called 'validate' to the CreditCard class here:
@ -45,18 +49,18 @@ class CreditCard:
# print(CreditCard.luna_check('4485040993287616')) # # print(CreditCard.luna_check('4485040993287616'))
cc = CreditCard('4485040993287616') # cc = CreditCard('4485040993287616')
print(cc.is_valid) # print(cc.is_valid)
exit(0) # exit(0)
#do not modify assert statements #do not modify assert statements
cc = CreditCard('9999999999999999') cc = CreditCard('9999999999999999')
assert cc.is_valid == False, "Credit Card number cannot start with 9" assert(cc.is_valid == False)
assert cc.card_type == "INVALID", "99... card type is INVALID" assert(cc.card_type == "INVALID")
cc = CreditCard('4440') cc = CreditCard('4440')