forked from course-work/week1
done
This commit is contained in:
parent
54a46068fb
commit
21366bead3
@ -21,7 +21,7 @@ def matrix_sum(matrix):
|
||||
|
||||
return row_sum, col_sum
|
||||
|
||||
def sort_row(matrix):
|
||||
def matrix_sort_row(matrix):
|
||||
row_sum, col_sum = matrix_sum(matrix)
|
||||
out = []
|
||||
|
||||
@ -30,7 +30,7 @@ def sort_row(matrix):
|
||||
|
||||
return out;
|
||||
|
||||
def sort_col(matrix):
|
||||
def matrix_sort_col(matrix):
|
||||
row_sum, col_sum = matrix_sum(matrix)
|
||||
out = []
|
||||
places = sorted( [i for i in enumerate(col_sum)], key=lambda x:x[1])
|
||||
|
@ -1,14 +1,15 @@
|
||||
class CreditCard:
|
||||
card_types = [
|
||||
('4', 'VISA'),
|
||||
('34', 'AMEX'),
|
||||
('37', 'AMEX'),
|
||||
('51', 'MASTERCARD'),
|
||||
('52', 'MASTERCARD'),
|
||||
('53', 'MASTERCARD'),
|
||||
('54', 'MASTERCARD'),
|
||||
('55', 'MASTERCARD'),
|
||||
('6011', 'DISCOVER'),
|
||||
# (starts with digits, card type, card length)
|
||||
('4', 'VISA', 16),
|
||||
('34', 'AMEX', 15),
|
||||
('37', 'AMEX', 15),
|
||||
('51', 'MASTERCARD', 16),
|
||||
('52', 'MASTERCARD', 16),
|
||||
('53', 'MASTERCARD', 16),
|
||||
('54', 'MASTERCARD', 16),
|
||||
('55', 'MASTERCARD', 16),
|
||||
('6011', 'DISCOVER', 16),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
@ -23,21 +24,24 @@ class CreditCard:
|
||||
return not bool(sum(digits) % 10)
|
||||
|
||||
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):
|
||||
for start, type in self.card_types:
|
||||
def __card_type(self):
|
||||
for start, type, length 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:
|
||||
def check_length(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
def is_valid(self):
|
||||
return self.luna_check(self.card_number), self.card_type
|
||||
return type, length
|
||||
|
||||
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:
|
||||
|
||||
@ -45,18 +49,18 @@ class CreditCard:
|
||||
|
||||
|
||||
|
||||
# print(CreditCard.luna_check('4485040993287616'))
|
||||
cc = CreditCard('4485040993287616')
|
||||
# # print(CreditCard.luna_check('4485040993287616'))
|
||||
# cc = CreditCard('4485040993287616')
|
||||
|
||||
print(cc.is_valid)
|
||||
exit(0)
|
||||
# print(cc.is_valid)
|
||||
# exit(0)
|
||||
|
||||
#do not modify assert statements
|
||||
|
||||
cc = CreditCard('9999999999999999')
|
||||
|
||||
assert cc.is_valid == False, "Credit Card number cannot start with 9"
|
||||
assert cc.card_type == "INVALID", "99... card type is INVALID"
|
||||
assert(cc.is_valid == False)
|
||||
assert(cc.card_type == "INVALID")
|
||||
|
||||
cc = CreditCard('4440')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user