{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Fall.2009.CSC108

# Fall.2009.CSC108 - IN EA PL N D H A SE UNIVERSITY OF...

This preview shows pages 1–5. Sign up to view the full content.

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

View Full Document
December 2009 Final Examination CSC 108 H1F 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 #: cont’d . . .
December 2009 Final Examination CSC 108 H1F 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? Page 3 of 20 Student #: cont’d . . .

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

View Full Document
December 2009 Final Examination CSC 108 H1F Question 3. [8 marks] Part (a) [5 marks] Write the function unique_values according to its docstring: def unique_values(d): ’’’Return a sorted list containing all the values (not keys) in dict d.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 20

Fall.2009.CSC108 - IN EA PL N D H A SE UNIVERSITY OF...

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

View Full Document
Ask a homework question - tutors are online