20101_exam - P L E A S E H A N D I N UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2010 EXAMINATIONS CSC108H1S Instructors Horton

Info iconThis preview shows pages 1–5. 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

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: P L E A S E H A N D I N UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2010 EXAMINATIONS CSC108H1S Instructors: Horton Duration — 3 hours P L E A S E H A N D I N Examination Aids: None Student Number: Family Name(s): Given Name(s): Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully . This final examination paper consists of 10 questions on 20 pages (including this one). When you receive the signal to start, please make sure that your copy of the final examination is complete. Comments and docstrings are not required except where indicated, although they may help us mark your answers. They may also get you part marks if you can’t figure out how to write the code. You do not need to put import statements in your answers. You may not use break or continue on this exam. If you use any space for rough work, indicate clearly what you want marked. Assume all input is valid unless otherwise indicated; there is no need to error-check. # 1: / 7 # 2: / 6 # 3: / 6 # 4: /12 # 5: / 6 # 6: /18 # 7: / 7 # 8: / 6 # 9: /10 # 10: / 8 TOTAL : /86 Page 1 of 20 Good Luck! cont’d ... April 2010 Final Examination CSC108H1S Question 1. [7 marks] Part (a) [3 marks] Write the following function, according to its docstring: def flip_lists(L): ’’’L is a list of 2-element lists. Reverse the order of the elements in the sublists of L.’’’ Part (b) [4 marks] Write the following function, according to its docstring: def valid_sizes(L, a, b): ’’’L is a list of lists; a and b are ints; a <= b. Return True iff each sublist has size between a and b inclusive.’’’ Page 2 of 20 Student #: cont’d ... April 2010 Final Examination CSC108H1S Question 2. [6 marks] Write the following function, according to its docstring: def interleave(s1, s2): ’’’Return a new string that contains the characters of string s1 and string s2 "interleaved" so that it contains the first character of s1, the first character of s2, the second character of s1, the second character of s2, etc. If one string is longer than the other, the "extra" characters are added on at the end. For example, interleave("ab", "12345") returns "a1b2345".’’’ Page 3 of 20 Student #: cont’d ... April 2010 Final Examination CSC108H1S Question 3. [6 marks] The left-hand column in the table below shows a series of code fragments to be interpreted by the Python shell. For each, show the expected output in the right-hand column; if it would generate an error say so, and give the reason why. Hint: Use the memory model to predict what will happen. The next page is provided for your rough work. Code Output (or “error” plus reason) x = (1, 2, 3) for item in x: item = item + 1 print x x = (1, 2, 3) for i in range(len(x)): x[i] = x[i] + 1 print x x = ([1, 2], , [8, 9, 3]) for item in x: item.append(5) print x x = [6, 7, 8] for item in x: item = item + 1 print x x = [6, 7, 8] for i in range(len(x)): x[i] = x[i] + 1...
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- Toronto.

Page1 / 20

20101_exam - P L E A S E H A N D I N UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2010 EXAMINATIONS CSC108H1S Instructors Horton

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

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