Python Program to Check if a String is a Pangram or Not

This is a Python Program to check if a string is a pangram or not.

Problem Description

The program takes a string and checks if it is a pangram or not.

Problem Solution

1. Take a string from the user and store it in a variable.
2. Pass the string as an argument to a function.
3. In the function, form two sets- one of all lower case letters and one of the letters in the string.
4. Subtract these both sets and check if it is equal to an empty set.
5. Print the final result.
6. Exit.

Program/Source Code

Here is source code of the Python Program to check if a string is a pangram or not. The program output is also shown below.

from string import ascii_lowercase as asc_lower
def check(s):
    return set(asc_lower) - set(s.lower()) == set([])
strng=raw_input("Enter string:")
if(check(strng)==True):
      print("The string is a pangram")
else:
      print("The string isn't a pangram")
Program Explanation

1. User must enter a string and store it in a variable.
2. The string is passed as an argument to a function.
3. In the function, two sets are formed- one for all lower case letters and one for the letters in the string.
4. The two sets are subtracted and if it is an empty set, the string is a pangram.
6. The final result is printed.

advertisement
advertisement
Runtime Test Cases
 
Case 1:
Enter string:The quick brown fox jumps over the lazy dog
The string is a pangram
 
Case 2:
Enter string:Hello world
The string isn't a pangram

Sanfoundry Global Education & Learning Series – Python Programs.

To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.

Note: Join free Sanfoundry classes at Telegram or Youtube

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.