Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Python! Thanks 3. (Pangrams, 15pt) A pangram is a sentence in which every

ID: 3875583 • Letter: U

Question

Using Python! Thanks

3. (Pangrams, 15pt) A pangram is a sentence in which every letter of the (English alphabet) occurs at least once (upper or lower case); the most famous example, often taken for typing practice, is The quick brown fox jumps over the lazy dog' (for more examples, see the wikipedia entry on pangrams). Write a function letter check(s) that takes a string s as an input, and counts the number of distinct letters in s; if there are 26 different letters, the function prints the message that you found a pangram, otherwise it tells you how many distinct letters there are in s. See below for test-runs L Python 3.5.2 Shell File Edit Shell Debug Options Window Help >>>letter_check ('the quick brown fox jumped over the fence) Your text contains only 20 different letters >>letter check ('the quick brown fox jumped over the lazy dog) Your text contains only 25 different letters >>letter check ( 'the quick brown fox jumps over the lazy dog') You got a pangram >>>letter check 'pack my box with five dozen liquor jugs') You got a pangram Ln: 36 Col: 4 Hint: remember that it doesn't matter whether the letters are lower or upper case. Research the string module to figure out a) a way to turn a string into an all lower-case version, and b) an easy way to get a list of all lower-case letters (there is a predefined constant). Finally, the count method will be useful

Explanation / Answer

The code was written in Python 3. You might have to edit some syntax to run on 2.7.

This gives you the same output as above. You can use convert to lower case function also.


myPhrase = "the quick brown fox jumps over the lazy dog"

def is_pangram(phrase):
c = 0
alphabet = "abcdefghijklmnopqrstuvwxyz"
phraseLetters = ""
for char in phrase:
for letter in alphabet:
if char == letter and char not in phraseLetters:
phraseLetters += char
for char in phraseLetters:
for letter in alphabet:
if char == letter:
c += 1
if c == 26:
print ("your text is a pangram")
else:
print ("your text contains ", len(phraseLetters)," letters")
  

print (is_pangram(myPhrase))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote