~2004.Midterm.Solutions.pdf

4 Pages
64 Views

Department
Computer Science
Course Code
CSC207H1
Professor
Diane Horton

This preview shows page 1. Sign up to view the full 4 pages of the document.
Description
Question 1. [4 marks] E3 part 3 asked you to write a Python tool SummarizeLog.py, which was called as follows: python SummarizeLog.py [-d startDate endDate] The square brackets indicated that these three arguments were optional. Part (a) [2 marks] What improvement could be made to this interface to make it more conventional or standard? Make the options 2 flags: -s startDate -e endDate and allow them to come in either order Part (b) [2 marks] How would that have benefitted the programmers who wrote SummarizeLog.py? They could have use standard command line parsing modules, and in particular getopt. Question 2. [4 marks] Part (a) [2 marks] What effect does setting a breakpoint have? Sets a point where the code will stop executing Part (b) [2 marks] When do the “Step into” and “Step over” buttons cause the same behaviour? When the current line of code has no method call. Student #: Page 1 of 4 cont’d... Question 3. [10 marks] The following code produces this output: [’hey’, ’dude’, ’lol’, "It’s", ’my’, ’bad’] # Module coolTester.py | # Module myErrors.py from cool import CoolTalker | # An exception indicating that there from myErrors import NoTranslationError | # is no translation for a word. | class NoTranslationError(ValueError): translator = CoolTalker() | def __init__(self): translator.addWord("hey", "hello") | ValueError.__init__(self) translator.addWord("dude", "friend") translator.addWord("bad", "fault") translator.addWord("lol", "ha") sentence = ["hello", "friend", "ha", "It’s", "my", "fault"] newSentence=[] for word in sentence: try: newWord = translator.toCool(word) except NoTranslationError: newWord = word newSentence.append(newWord) print newSentence Write module cool.py. from myErrors import NoTranslationError class CoolTalker: def __init__(self): self.NormalToCool={} def addWord(self,cool,normal): self.NormalToCool[normal] = cool def toCool(self,normal): if normal in self.NormalToCool.keys(): return self.NormalToCool[normal] else: raise NoTranslationError Student #: Page 2 of 4 cont’d... Question 4. [7 marks] Consider the following Makefile. #============================================================================ # Makefile : for question 4 of stg midterm COMPILE_JAVA = javac -classpath ${CSC207PATH} -source 1.4 RUN_JAVA = java -classpath ${CSC207PATH} -enableassertions test: MyTests.class ${RUN_JAVA} MyTests < testFile.01.txt MyTests.class: MyAssignment.class MyException.class MyAssignment.class: MyException.class hat: MyAssignment.class ${RUN_JAVA} MyAssignment -c 12 hat < ${TEST_INPUT} house: MyAssignment.class ${RUN_JAVA} MyAssignment -c 10 house < ${TEST_INPUT} > result both: hat house clean : @rm -f *~ *.class %.class : %.java @${COMPILE_JAVA} $< Part (a) [1
More Less
Unlock Document

Only page 1 are available for preview. Some parts have been intentionally blurred.

Unlock Document
You're Reading a Preview

Unlock to view full version

Unlock Document

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit