Task 2. PangramsAvailable Marks: 9A pangram is a phrase that contains at least one instance of each of the 26 letters of the alphabet, ignoring differences between upper and lower case. The quick brown fox jumps over the lazy dog is probably the most well-known pangram, but with advent of computer processing many more have been devised. Write a program that processes a file containing up to 50 phrases, one per line, each up to 120 characters in length. The first line contains the number of phrases. The program should display each phrase, and on the next line, indented so we can see it easily, either: ExampleInput:
Output:
Test DataYou should test your program on the following data:
# Task 2: Pangrams - use all 26 letters of alphabet is a sentence # alphabet = [ 'a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' ,'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o' ,'p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' ,'x' ,'y' ,'z' ] ##inp = [ ## '4' ##,'the quick brown fox jumps over the lazy possum' ##,'Many-wived Jack laughs at probes of sex quiz.' ##,'CHEEKY JUVENILE DELINQUENTS BLAME LAX PARENTAL CONTROLS FOR WANTON VANDALIZING' ##,'pangram' ##]; # Open a file fo = open("pangram_input.txt", "r") str=fo.read(); #print(str); fo.close(); inp = str.splitlines(); # creates a list from the file input separated by \n (default) first = True; for sentence in inp: #Go through the INPUT list, entry by entry. An entry is a sentence sentence = sentence.lower(); ## alpha_used = []; letter_unused = ''; pangram = True; if (first): maxcount = int(sentence); first = False; continue; else: for letter in alphabet: if (sentence.find(letter)<0): letter_unused = letter_unused+letter; pangram = False; print('> {0}'.format(sentence)); if (pangram): print(' Pangram'); else: print(' Not a Pangram, does not contain: {0}'.format(letter_unused)) |
