Skip to Main Content
Blog

Check Pangram String in Python

Check Pangram String in Python

Write a Java program that accepts a string from the user and determines whether it is a pangram. If it is not, prints all the missing letters.A pangram is defined as a sentence or phrase that includes every letter of a specified alphabet (typically English) at least once.

Output

## Example 1
Enter string: The quick brown fox jumps over the lazy dog.
Pangram

## Example 2
Enter string: The lazy dog was caught by the quick brown fox.
Not Pangram
Missing Letters: jmpv

## Example 3
Enter string: Mr. Jock, TV quiz PhD, bags few lynx
Pangram

Solution

def main():
	text = input("Enter string: ")

	count = frequency(text)
	is_pangram = all(value > 0 for value in count)

	print("Pangram" if is_pangram else "Not Pangram")

	# Print the missing letters
	if not is_pangram:
		print("Missing Letters: ", end="")
		for i, value in enumerate(count):
			if value == 0:
				print(chr(ord("a") + i), end="")
		print()


def frequency(text: str):
	count = [0] * 26
	for c in text.lower():
		if "a" <= c <= "z":
			count[ord(c) - ord("a")] += 1
	return count


if __name__ == "__main__":
	main()