CSCA08H3 Final: CSCA08H3 Final Exam 2012 Fall

118 views20 pages
16 Oct 2018
School
Course
Professor
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...
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 20 pages and 3 million more documents.

Already have an account? Log in
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...
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 20 pages and 3 million more documents.

Already have an account? Log in
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...
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 20 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully. This nal 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 nal 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 gure 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. For each code fragment in the table below, indicate whether or not the code causes an error.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents