Given a sentence. Our task is to check whether this sentence is pan grams or not. The logic of Pan grams checking is that words or sentences containing every letter of the alphabet at least once. To solve this problem we use set () method and list comprehension technique.
Input: string = 'abc def ghi jkl mno pqr stu vwx yz' Output: Yes // contains all the characters from ‘a’ to ‘z’ Input: str='python program' Output: No // Does not contains all the characters from ‘a’ to 'z'
Step 1: create a string. Step 2: Convert the complete sentence to a lower case using lower () method. Step 3: convert the input string into a set (), so that we will list of all unique characters present in the sentence. Step 4: separate out all alphabets ord () returns ASCII value of the character. Step 5: If length of list is 26 that means all characters are present and sentence is Pangram otherwise not.
def checkPangram(s): lst =  for i in range(26): lst.append(False) for c in s.lower(): if not c == " ": lst[ord(c) -ord('a')]=True for ch in lst: if ch == False: return False return True # Driver Program str1=input("Enter The String ::7gt;") if (checkPangram(str1)): print ('"'+str1+'"') print ("is a pangram") else: print ('"'+str1+'"') print ("is not a pangram")
Enter The String ::abc def ghi jkl mno pqr stu vwx yz "abc def ghi jkl mno pqr stu vwx yz" is a pangram Enter The String ::> python program "pyhton program" is not a pangram