We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Self-documenting code is ostensibly written using human-readable names, typically consisting of a phrase in a human language which reflects the symbol's meaning, such as article.
importredefis_valid_credit_card(card_number:str)->str:"""Check if the card_number is valid or not,validnumberhasthefollowingcharacteristics:Itmuststartwitha4,5or6.Itmustcontainexactly16digits.Itmustonlyconsistofdigits(0-9).Itmayhavedigitsingroupsof4,separatedONLYbyonehyphen"-".ItmustNOThave4ormoreconsecutiverepeateddigits."""pattern=re.compile(r'^(?!.*(\d)(-?\1){3})[456]\d{3}-?\d{4}-?\d{4}-?\d{4}$')ifpattern.match(card_number):return"Valid"return"Invalid"number_of_cards=int(input())for_inrange(number_of_cards):card_to_check=input()print(is_valid_credit_card(card_to_check))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Validating Credit Card Numbers
You are viewing a single comment's thread. Return to all comments →
Self-documenting code is ostensibly written using human-readable names, typically consisting of a phrase in a human language which reflects the symbol's meaning, such as article.