Fall.2009.CSC108 - P L E A S E H A N D I N UNIVERSITY OF...

Info iconThis preview shows pages 1–4. 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 DECEMBER 2009 EXAMINATIONS CSC108 H1F Instructors: Gries, Horton, Zingaro 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 12 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 cant 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: /10 # 2: / 6 # 3: / 8 # 4: / 8 # 5: /12 # 6: /10 # 7: /12 # 8: / 3 # 9: /10 # 10: / 4 # 11: / 5 # 12: / 6 TOTAL : /94 Page 1 of 20 Good Luck! contd ... December 2009 Final Examination CSC108H1F Question 1. [10 marks] Below are five segments of code. Each one runs without error. To the right of each segment, show the output it generates. L = [1, 2, 3, 4] for item in L: item = item * 5 print L Output: L = [["a", "b"], ["c", "d"]] for item in L: item.append("0") print L Output: s = "pizzapizza" count = 0 i = 1 while i < len(s): if s[i] > "m": count = count + 1 i = i + 1 print count Output: def change(s): s = s + "!" word = "holiday" change(word) print word Output: def alter(d): d["Dec"] = "vacation!" months = {"Jan": "school"} alter(months) print months Output: Page 2 of 20 Student #: contd ... December 2009 Final Examination CSC108H1F Question 2. [6 marks] Consider the following code fragments: # Code fragment 1 for char in s: print char for char in s: print char + char for char in s: print char + char + char for char in s: print char + char + char + char for char in s: print char + char + char + char + char # Code fragment 2 for char_1 in s: for char_2 in s: for char_3 in s: print char_1 + char_2 + char_3 Part (a) [1 mark] If we assign the value "bumble" to s and execute code fragment 1, how many lines of output will be produced? Part (b) [2 marks] In general, for a string of length n , how many lines of output will be produced by code fragment 1? Part (c) [1 mark] If we assign the value "bumble" to s and execute code fragment 2, how many lines of output will be produced? Part (d) [2 marks] In general, for a string of length n , how many lines of output will be produced by code fragment 2?...
View Full Document

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

Page1 / 20

Fall.2009.CSC108 - P L E A S E H A N D I N UNIVERSITY OF...

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

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