Check Pangram in Python

Check whether a sentence is a pangram (contains every letter of the alphabet at least once).

IntermediateString ProgramsExample 24 of 25
check-pangram.py
1# Program to check pangram
2
3import string
4
5sentence = input("Enter a sentence: ").lower()
6
7alphabet_set = set(string.ascii_lowercase)
8letters = set(ch for ch in sentence if ch.isalpha())
9
10if alphabet_set.issubset(letters):
11 print("Pangram")
12else:
13 print("Not a pangram")

Output

Enter a sentence: The quick brown fox jumps over the lazy dog
Pangram

What's going on

We compare the set of all lowercase letters with the set of letters present in the sentence.

After this program

If the idea is still fuzzy, read Day 4: Strings and String Methods in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 25 string programs, or see every topic on Python exercises.