Do not write on this question sheet – write only on the ...



Do not write on this question sheet – write only on the answer sheet. Please write legibly, and if your indentation might be confusing, use some symbols to indicate where you’ve indented.

This test is out of 100 points, with and additional 10 points extra credit.

1. (25 points) Create a function called NoPunc(s) which will be given a string containing words along with punctuation. Remove all punctuation from the string (leave the spaces, though) and return the resultant string. The punctuation symbols you need to worry about are: period, comma, colon, semi-colon, question-mark and exclamation-mark.

2. Now that you’ve removed all punctuation from the string, we’re interested in the words. Some of them are long, some are short. There may be a few words that are the longest (for instance, 15 characters), and perhaps many words which are the second longest (say, 13 characters, assuming that there are no words with 14 characters).

For instance, if the string is: “Now is the time for all Python freaks to be clearly worried”, the longest words are “clearly” and “worried”, and the second longest words are “Python” and “freaks”.

2a) (10 points) Create the function LongestWords(s) which will return a list of all the longest words in s. For instance, for the string in the example above, it will return [‘clearly’,’worried’].

2b) (15 points) Create the function SecondLongestWords(s) which will return a list of all the words in s, which are second longest. For instance, for the string in the example above, it will return [‘Python’,’freaks’].

3. (25 points) You and your friend, Voldy, are each given a gadget that’s similar to a compass. It gives a digital readout, in whole number degrees, showing which direction you’re headed. Let’s say you’re facing North when you turn it on – it will immediately show “0”. As you turn clock-wise, the numbers will increase, so that when you are facing East, it shows “90”, and when you reach South, it shows “180”, and then West: “270” and North again: “360”. If you keep turning clockwise, the numbers will keep increasing, so that if you reach East again, it shows “450”, etc. When reversing your direction – turning counter-clockwise – the gadget’s numbers decrease. In fact, it may become negative (say “-90” when facing West). Assume that you’re both facing North when you turn on your gadgets (so the initial readings are both “0”).

Create the function MinDiff(mine,his) that is given the readouts from my gadget and his, and returns the (minimum) angle difference between our two headings. This number is the measure of the minor arc between the headings.

It will be in the range 0 ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download