20101_t2_solution - CSC108H1S Test 2 — Solutions Winter...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSC108H1S Test 2 — Solutions Winter 2010 Question 1. [3 marks] For each of the following snippets of code, write the output that it would produce, or write “Error” if it would cause an error. Code Output (or “Error”) d1 = { [1, 2]: "a", [3]: "z" } print d1.keys() d2 = { 1: 2, 5: 9, -3: 4 } ans = 1 for k in d2: ans = ans * k print ans d3 = { "hello": "goodbye", "fee": "fi" } print d3["hello"].upper()[5] + "am" Solution: • Error (Keys must be immutable and lists are not immutable.) •-15 • Yam (with a capital “Y”) Student #: Page 1 of 5 cont’d . . . CSC108H1S Test 2 — Solutions Winter 2010 Question 2. [5 marks] Complete the following function according to its docstring description. For the purpose of this question, a word is defined to be a string that is delineated by white space (blanks, tabs and newline characters). You must not store more than one line of the file at a time. Answers that do will receive a mark of zero ....
View Full Document

This note was uploaded on 09/19/2011 for the course CSC 108 taught by Professor Gries during the Fall '08 term at University of Toronto.

Page1 / 5

20101_t2_solution - CSC108H1S Test 2 — Solutions Winter...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online