Home‎ > ‎ProgComp‎ > ‎ProgComp 2012 Sample Tasks‎ > ‎

Task 2. Pangrams



Task 2. Pangrams

Available Marks: 9

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: 

Pangram (if it is), or
Not a pangram, does not contain: xyz (where xyz are all the letters not present in the phrase, in alphabetic order)

Example

Input:

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

Output:

the quick brown fox jumps over the lazy possum
  Not a pangram, does not contain: dg
Many-wived Jack laughs at probes of sex quiz.
  Pangram
CHEEKY JUVENILE DELINQUENTS BLAME LAX PARENTAL CONTROLS FOR WANTON VANDALIZING
  Pangram
pangram
  Not a pangram, does not contain: bcdefhijkloqstuvwxyz

Test Data

You should test your program on the following data:
15
jackdaws love my big sphinx of quartz
Five or six big jet planes zoom quickly by the tower.
PR flacks quiz gym: TV DJ box when?
Amazingly few discotheques provide jukeboxes.
Six big juicy steaks sizzled in a pan as five workers left the quarry.
UNSW Computing Progcomp
A quart jar of oil mixed with zinc oxide makes very bright paint.
He wrote deftly and quickly, amazing us with his expertise and his unabashed love of letters.

Portez ce vieux whisky au juge blond qui fume.
(French: Take this old whiskey to the blond judge who smokes)
Five hexing wizard bots jump quickly.
B, C, F, G, H, I, J, K, M, P, Q, U, V, W, X, Y, and Z are letters.
The job requires extra pluck and zeal from every staff member.
Six calligraphers, justly amazed, watch kids busily cutting quills with their favourite penknives.




# 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))


Comments