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

CSCA08H3 Final: CSCA08H3 Final Exam 2012 FallExam


Department
Computer Science
Course Code
CSCA08H3
Professor
All
Study Guide
Final

This preview shows pages 1-3. to view the full 20 pages of the document.
UNIVERSITY OF TORONTO
Department of Computer and
Mathematical Science
DECEMBER 2012 EXAMINATIONS
CSC A08 H3F
Instructor: Brian Harrington
Duration — 3 hours
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 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: /8
# 2: /4
# 3: /2
# 4: /4
# 5: /5
# 6: /10
# 7: /5
# 8: /9
# 9: /10
# 10: /10
# 11: /3
# 12: /2
TOTAL:/72
Page 1 of 20 Good Luck! cont’d...

Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

December 2012 Final Examination CSC A08 H3F
Question 1. [8 marks]
For each code fragment in the table below, indicate whether or not the code causes an error. If it runs
without error, give the output. If it has an error, explain the cause of the error.
Code Error? Output or Cause of Error
(yes or no)
print(9 / 5)
print(9 // 5)
print(9 % 5)
a = [1, 2, 3, 4, 5]
print(a[3])
b = [’hello’, ’world’]
print(b[2])
c = ’moogah’
c[0] = ’b’
print(c[0])
d={2: [’sam’, ’pat’, ’carl’],
0: [’little’, ’bo’, ’peep’],
1: [’tina’, ’jo’]}
print(d[0][-1][1:])
e = [’A’, ’B’, ’C’]
e[0] = 8663
print(e)
Page 2 of 20 cont’d...

Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

December 2012 Final Examination CSC A08 H3F
Question 2. [4 marks]
In the box below, write what is printed when the following program is executed.
def square(x):
print(’Squaring’, x)
return x * x
def add(y, z):
print(’Adding’, y, z)
return y + z
if add(-25, square(5)) > 0 and add(-4, square(10)) > 0:
print(’Woohoo!’)
else:
print(’Rats’, add(square(3), 0))
Page 3 of 20 Student #: cont’d...
You're Reading a Preview

Unlock to view full version