Study Guides (380,000)
CA (150,000)
UTSC (10,000)
All (20)
Midterm

CSCA08H3 Midterm: CSCA08H3 Midterm 2012 Fall SolutionsExam


Department
Computer Science
Course Code
CSCA08H3
Professor
All
Study Guide
Midterm

This preview shows page 1. to view the full 5 pages of the document.
CSCA08_Mid_2012F Solution
Question 1 part a)
Solution
7 9
Explanation
Since ints are immutable, when we initialize <y> to <x> plus 5, the value of <y>
is not reliant on that of <x> after that declaration.
We can change <x> afterwards, as we do to 7, and this will have no effect on
<y>. Thus leaving <y> as 4 + 5 9, and the second last line then sets <x> to 7.
Question 1 part b)
Solution
C
S
C
Explanation
This while-loop executes as long as our index variable <i> is less than the length
of the string <s> and the current letter that we are looking at (s[i]) is part of the
alphabet.
CSC are part of the alphabet and within the context of the string <s>, hence why
they are the first three letters printed, but then we hit the hyphen, which fails the latter
and check, and thus the while-loop exits.
You're Reading a Preview

Unlock to view full version

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

Question 1 part c)
Solution
return age > 70 or has_vip_card
Explanation
We only return true if the age is greater than 70 or <has_vip_card> is True
Question 1 part d)
Solution
s1[3:5] + s2[0] + s1[3]
Explanation
s1[3:5] = ‘te’
s2[0] = ‘s’
s1[3] = ‘t’
‘te’ + ‘s’ + ‘t’ ‘test’
Question 2 part a)
Solution
def case_inversion (s):
‘’’ (str) -> str
Return a copy of <s> with the cases inverted.
>>> case_inversion (‘Hi’)
You're Reading a Preview

Unlock to view full version