mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-20 05:29:48 +00:00
Fix validate_initial_digits of credit_card_validator.py (#5600)
* Fix validate_initial_digits of credit_card_validator.py @Bhargavishnu I think that I broke the logic of validate_initial_digits which should require that credit_card_number[0] is 3 before checking that credit_card_number[1] is 4, 5, or 7. Please verify the new changes and the new test cases to make sure that this is correct. Thanks! * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
700398ec06
commit
366a0f1839
@ -944,6 +944,7 @@
|
|||||||
* [Capitalize](https://github.com/TheAlgorithms/Python/blob/master/strings/capitalize.py)
|
* [Capitalize](https://github.com/TheAlgorithms/Python/blob/master/strings/capitalize.py)
|
||||||
* [Check Anagrams](https://github.com/TheAlgorithms/Python/blob/master/strings/check_anagrams.py)
|
* [Check Anagrams](https://github.com/TheAlgorithms/Python/blob/master/strings/check_anagrams.py)
|
||||||
* [Check Pangram](https://github.com/TheAlgorithms/Python/blob/master/strings/check_pangram.py)
|
* [Check Pangram](https://github.com/TheAlgorithms/Python/blob/master/strings/check_pangram.py)
|
||||||
|
* [Credit Card Validator](https://github.com/TheAlgorithms/Python/blob/master/strings/credit_card_validator.py)
|
||||||
* [Detecting English Programmatically](https://github.com/TheAlgorithms/Python/blob/master/strings/detecting_english_programmatically.py)
|
* [Detecting English Programmatically](https://github.com/TheAlgorithms/Python/blob/master/strings/detecting_english_programmatically.py)
|
||||||
* [Frequency Finder](https://github.com/TheAlgorithms/Python/blob/master/strings/frequency_finder.py)
|
* [Frequency Finder](https://github.com/TheAlgorithms/Python/blob/master/strings/frequency_finder.py)
|
||||||
* [Indian Phone Validator](https://github.com/TheAlgorithms/Python/blob/master/strings/indian_phone_validator.py)
|
* [Indian Phone Validator](https://github.com/TheAlgorithms/Python/blob/master/strings/indian_phone_validator.py)
|
||||||
@ -961,6 +962,7 @@
|
|||||||
* [Rabin Karp](https://github.com/TheAlgorithms/Python/blob/master/strings/rabin_karp.py)
|
* [Rabin Karp](https://github.com/TheAlgorithms/Python/blob/master/strings/rabin_karp.py)
|
||||||
* [Remove Duplicate](https://github.com/TheAlgorithms/Python/blob/master/strings/remove_duplicate.py)
|
* [Remove Duplicate](https://github.com/TheAlgorithms/Python/blob/master/strings/remove_duplicate.py)
|
||||||
* [Reverse Letters](https://github.com/TheAlgorithms/Python/blob/master/strings/reverse_letters.py)
|
* [Reverse Letters](https://github.com/TheAlgorithms/Python/blob/master/strings/reverse_letters.py)
|
||||||
|
* [Reverse Long Words](https://github.com/TheAlgorithms/Python/blob/master/strings/reverse_long_words.py)
|
||||||
* [Reverse Words](https://github.com/TheAlgorithms/Python/blob/master/strings/reverse_words.py)
|
* [Reverse Words](https://github.com/TheAlgorithms/Python/blob/master/strings/reverse_words.py)
|
||||||
* [Split](https://github.com/TheAlgorithms/Python/blob/master/strings/split.py)
|
* [Split](https://github.com/TheAlgorithms/Python/blob/master/strings/split.py)
|
||||||
* [Upper](https://github.com/TheAlgorithms/Python/blob/master/strings/upper.py)
|
* [Upper](https://github.com/TheAlgorithms/Python/blob/master/strings/upper.py)
|
||||||
|
@ -11,13 +11,11 @@ def validate_initial_digits(credit_card_number: str) -> bool:
|
|||||||
>>> valid = "4111111111111111 41111111111111 34 35 37 412345 523456 634567"
|
>>> valid = "4111111111111111 41111111111111 34 35 37 412345 523456 634567"
|
||||||
>>> all(validate_initial_digits(cc) for cc in valid.split())
|
>>> all(validate_initial_digits(cc) for cc in valid.split())
|
||||||
True
|
True
|
||||||
>>> invalid = "32323 36111111111111"
|
>>> invalid = "14 25 76 32323 36111111111111"
|
||||||
>>> all(validate_initial_digits(cc) is False for cc in invalid.split())
|
>>> all(validate_initial_digits(cc) is False for cc in invalid.split())
|
||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
if len(credit_card_number) < 2:
|
return credit_card_number.startswith(("34", "35", "37", "4", "5", "6"))
|
||||||
return False
|
|
||||||
return credit_card_number[0] in "456" or credit_card_number[1] in "457"
|
|
||||||
|
|
||||||
|
|
||||||
def luhn_validation(credit_card_number: str) -> bool:
|
def luhn_validation(credit_card_number: str) -> bool:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user