done
This commit is contained in:
		| @ -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') | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user