Skip to content

Commit 981ae7f

Browse files
Merge pull request #670 from terror/add-check-pangram
add check pangram
2 parents 4867816 + e5ffcb4 commit 981ae7f

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ If you want to uninstall algorithms, it is as simple as:
325325
- [judge_circle](algorithms/strings/judge_circle.py)
326326
- [strong_password](algorithms/strings/strong_password.py)
327327
- [caesar_cipher](algorithms/strings/caesar_cipher.py)
328+
- [check_pangram](algorithms/strings/check_pangram.py
328329
- [contain_string](algorithms/strings/contain_string.py)
329330
- [count_binary_substring](algorithms/strings/count_binary_substring.py)
330331
- [repeat_string](algorithms/strings/repeat_string.py)

algorithms/strings/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from .judge_circle import *
2626
from .strong_password import *
2727
from .caesar_cipher import *
28+
from .check_pangram import *
2829
from .contain_string import *
2930
from .count_binary_substring import *
3031
from .repeat_string import *
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""
2+
Algorithm that checks if a given string is a pangram or not
3+
"""
4+
5+
def check_pangram(input_string):
6+
alphabet = "abcdefghijklmnopqrstuvwxyz"
7+
for ch in alphabet:
8+
if ch not in input_string.lower():
9+
return False
10+
return True

tests/test_strings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
judge_circle,
2929
strong_password,
3030
caesar_cipher,
31+
check_pangram,
3132
contain_string,
3233
count_binary_substring,
3334
repeat_string,
@@ -454,6 +455,11 @@ def test_caesar_cipher(self):
454455
self.assertEqual("Lipps_Asvph!", caesar_cipher("Hello_World!", 4))
455456
self.assertEqual("okffng-Qwvb", caesar_cipher("middle-Outz", 2))
456457

458+
class TestCheckPangram(unittest.TestCase):
459+
def test_check_pangram(self):
460+
self.assertTrue(check_pangram("The quick brown fox jumps over the lazy dog"))
461+
self.assertFalse(check_pangram("The quick brown fox"))
462+
457463

458464
class TestContainString(unittest.TestCase):
459465
def test_contain_string(self):

0 commit comments

Comments
 (0)