Skip to content

Commit 366a0f1

Browse files
cclaussgithub-actions
and
github-actions
authored
Fix validate_initial_digits of credit_card_validator.py (TheAlgorithms#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>
1 parent 700398e commit 366a0f1

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

DIRECTORY.md

+2
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@
944944
* [Capitalize](https://github.com/TheAlgorithms/Python/blob/master/strings/capitalize.py)
945945
* [Check Anagrams](https://github.com/TheAlgorithms/Python/blob/master/strings/check_anagrams.py)
946946
* [Check Pangram](https://github.com/TheAlgorithms/Python/blob/master/strings/check_pangram.py)
947+
* [Credit Card Validator](https://github.com/TheAlgorithms/Python/blob/master/strings/credit_card_validator.py)
947948
* [Detecting English Programmatically](https://github.com/TheAlgorithms/Python/blob/master/strings/detecting_english_programmatically.py)
948949
* [Frequency Finder](https://github.com/TheAlgorithms/Python/blob/master/strings/frequency_finder.py)
949950
* [Indian Phone Validator](https://github.com/TheAlgorithms/Python/blob/master/strings/indian_phone_validator.py)
@@ -961,6 +962,7 @@
961962
* [Rabin Karp](https://github.com/TheAlgorithms/Python/blob/master/strings/rabin_karp.py)
962963
* [Remove Duplicate](https://github.com/TheAlgorithms/Python/blob/master/strings/remove_duplicate.py)
963964
* [Reverse Letters](https://github.com/TheAlgorithms/Python/blob/master/strings/reverse_letters.py)
965+
* [Reverse Long Words](https://github.com/TheAlgorithms/Python/blob/master/strings/reverse_long_words.py)
964966
* [Reverse Words](https://github.com/TheAlgorithms/Python/blob/master/strings/reverse_words.py)
965967
* [Split](https://github.com/TheAlgorithms/Python/blob/master/strings/split.py)
966968
* [Upper](https://github.com/TheAlgorithms/Python/blob/master/strings/upper.py)

strings/credit_card_validator.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ def validate_initial_digits(credit_card_number: str) -> bool:
1111
>>> valid = "4111111111111111 41111111111111 34 35 37 412345 523456 634567"
1212
>>> all(validate_initial_digits(cc) for cc in valid.split())
1313
True
14-
>>> invalid = "32323 36111111111111"
14+
>>> invalid = "14 25 76 32323 36111111111111"
1515
>>> all(validate_initial_digits(cc) is False for cc in invalid.split())
1616
True
1717
"""
18-
if len(credit_card_number) < 2:
19-
return False
20-
return credit_card_number[0] in "456" or credit_card_number[1] in "457"
18+
return credit_card_number.startswith(("34", "35", "37", "4", "5", "6"))
2119

2220

2321
def luhn_validation(credit_card_number: str) -> bool:

0 commit comments

Comments
 (0)