140k views
1 vote
Intro to Java CODING assignment
PLEASE HELP

Intro to Java CODING assignment PLEASE HELP-example-1
User JP Aquino
by
8.5k points

1 Answer

6 votes

Answer:

Here's a Python program that can determine if a sentence is a pangram or a perfect pangram based on the given input format:

import string

def is_pangram(sentence):

# Convert the sentence to lowercase and remove all non-alphabetic characters

sentence = sentence.lower().replace(" ", "").replace(".", "").replace(":", "").replace("\"", "")

# Create a set of unique characters in the sentence

unique_chars = set(sentence)

# Check if the set of unique characters contains all 26 letters of the alphabet

if len(unique_chars) == 26:

return True

else:

return False

def is_perfect_pangram(sentence):

# Convert the sentence to lowercase and remove all non-alphabetic characters

sentence = sentence.lower().replace(" ", "").replace(".", "").replace(":", "").replace("\"", "")

# Create a set of unique characters in the sentence

unique_chars = set(sentence)

# Check if the set of unique characters contains all 26 letters of the alphabet

if len(unique_chars) == 26 and len(sentence) == 26:

return True

else:

return False

# Input sentences from the text file

sentences = [

"THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.",

"ALL YOUR BASE ARE BELONG TO US: SOMEONE SET US UP THE BOMB.",

"\"NOW FAX A QUIZ TO JACK!\" MY BRAVE GHOST PLED.",

"QUICK HIJINX SWIFTLY REVAMPED THE GAZEBO.",

"NEW JOB: FIX MR GLUCK'S HAZY TV, PDQ.",

"LOREM IPSUM DOLOR SIT AMET CONSECTETUR ADIPISCING ELIT.",

"PACK MY BOX WITH FIVE DOZEN LIQUOR JUGS."

]

# Iterate through the input sentences

for sentence in sentences:

# Check if the sentence is a perfect pangram

if is_perfect_pangram(sentence):

print("PERFECT:", sentence)

# Check if the sentence is a pangram

elif is_pangram(sentence):

print("PANGRAM:", sentence)

# If neither, print NEITHER

else:

print("NEITHER:", sentence)

This program uses two functions is_pangram() and is_perfect_pangram() to check if a sentence is a pangram or a perfect pangram, respectively. It then iterates through the input sentences and prints the appropriate output based on the pangram status of each sentence.

User Ernests Karlsons
by
8.5k points