
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python program to check a sentence is a pangrams or not.
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.
Example
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'
Algorithm
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.
Example Code
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")
Output
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
- Related Articles
- Program to check whether the sentence is pangram or not using Python
- Python program to check if a string is palindrome or not
- Program to check a string is palindrome or not in Python
- Python program to check whether a list is empty or not?
- Python program to check if a number is Prime or not
- Python program to check a number n is weird or not
- Program to check a number is ugly number or not in Python
- Python program to check whether a given string is Heterogram or not
- Python program to check if a given string is Keyword or not
- Python Program to Check Whether a String is a Palindrome or not Using Recursion
- Program to check whether a binary tree is complete or not in Python
- Program to check whether a binary tree is BST or not in Python
- Program to check a number is power of two or not in Python
- Golang Program to check a directory is exist or not
- Program to check given graph is a set of trees or not in Python

Advertisements