Check if a string is Pangrammatic Lipogram in Python

PythonServer Side ProgrammingProgramming

Suppose, we have been provided with three strings and we are asked to find which of the strings are a Pangram, Lipogram, and a Pangrammatic Lipogram. A Pangram is a string or a sentence, where every letter in the alphabet appears at least once. A Lipogram is a string or a sentence where one or more letters in the alphabet do not appear. A Pangrammatic Lipogram is a string or sentence where all letters in the alphabet appear except one.

So, if the input is like −

pack my box with five dozen liquor jugs
to stay in this mortal world or by my own hand go to oblivion, that is my conundrum.
the quick brown fox jumps over a lazy dog
waltz, nymph, for quick jigs ve bud,

then the output will be −

The String is a Pangram
The String isn't a Pangram but might be a Lipogram
The String is a Pangram
The String is a Pangrammatic Lipogram

To solve this, we will follow these steps −

  • convert all letters in the string to lowercase alphabets.
  • i := 0
  • for each character in the lowercase alphabet, do
    • if character is not found in input_string, then
      • i := i + 1
  • if i is same as 0, then
    • output := "The String is a Pangram"
  • otherwise when i is same as 1, then
    • output := "The String is a Pangrammatic Lipogram"
  • otherwise,
    • output := "The String isn't a Pangram but might be a Lipogram"
  • return output

Example

Let us see the following implementation to get better understanding −

 Live Demo

import string
def solve(input_string):
   input_string.lower()
   i = 0
   for character in string.ascii_lowercase:
      if(input_string.find(character) < 0):
         i += 1
   if(i == 0):
      output = "The String is a Pangram"
   elif(i == 1):
      output = "The String is a Pangrammatic Lipogram"
   else:
      output = "The String isn't a Pangram but might be a Lipogram"
   return output
print(solve("pack my box with five dozen liquor jugs"))
print(solve("to stay in this mortal world or by my own hand go to oblivion,that is my conundrum."))
print(solve("the quick brown fox jumps over a lazy dog"))
print(solve("waltz, nymph, for quick jigs ve bud"))

Input

pack my box with five dozen liquor jugs
to stay in this mortal world or by my own hand go to oblivion, that is my conundrum.
the quick brown fox jumps over a lazy dog
waltz, nymph, for quick jigs ve bud

Output

The String is a Pangram
The String isn't a Pangram but might be a Lipogram
The String is a Pangram
The String is a Pangrammatic Lipogram
raja
Published on 18-Jan-2021 11:53:46
Advertisements