Python Program to check the string is pangram or not


December 16, 2022, Learn eTutorial
1394

What is Pangram String?

A pangram string is a sentence that includes all the alphabets in the English language. Let us take a popular example of PangramThe quick brown fox jumps over a lazy dog" It has all the alphabets in the English language. Here is a python program for checking whether a string is a Pangram or not.

How do we check for the pangram string in python?

Now let us check how we do this pangram program in python. After accepting the user's string, we have to import ASCII values of all alphabets and save that to a variable. We call a function to check the pangram.

Inside that function, we subtract the total alphabets value and the letters in the string value, after converting both to lowercase. Check if the result is zero, then it's a pangram, else it's not a pangram. 

ALGORITHM

STEP 1: Import the ASCII values of all lowercase letters and store them in a variable. 

STEP 2: Accept the string from the user using the input method in python language. 

STEP 3: Call the function inside an if condition and check the return value from the function and if that is true or zero. 

STEP 4: Print the string is pangram else not pangram.

USER DEFINED FUNCTION check(s)

STEP 1: Accept the string as a parameter to the function to check the pangram or not.

STEP 2: Calculate the difference between the lowercase ASCII values of the total alphabets and the ASCII values of lowercase letters of the string and return the result to the calling function.

Python Source Code

                                          from string import ascii_lowercase as asc_lower
def check(s):
    return set(asc_lower) - set(s.lower()) == set([])

string=input("Enter string:")
if(check(string)==True):
      print("The string is a pangram")
else:
      print("The string isn't a pangram")
                                      

OUTPUT

Enter string:The quick brown fox jumps over the lazy dog

The string is a pangram