Page 1 of 22
UNIVERSITY OF TORONTO
Faculty of Arts & Science
December 2023 Examinations
CSC 108 H1F Do not turn this page
until you have received the signal to start.
Duration: 3 hours In the meantime,
please fill out the section below,
Aids Allowed: Provided aid sheet
and carefully read all instructions on this page.
First name (please write as legibly as possible within the boxes)
Last name
Student ID number (9 or 10 digits)
• This final examination consists of 14 questions on 22 pages (including this one), printed on both sides of the paper.
• Answer each question directly on the examination paper, in the space provided. There are several blank pages at
the end for rough work. Do not remove any pages from the exam booklet. If you need more space for one of
your solutions, use one of the blank pages and indicate clearly the part of your work that should be marked.
• We have provided an aid sheet with a list of useful Python function/method descriptions on a separate piece of
paper. Nothing you write on the aid sheet will be marked.
• Remember that, in order to pass the course, you must achieve a grade of at least 40% (28 marks) on this final
examination.
• As a student, you help create a fair and inclusive writing environment. If you possess an unauthorized aid during an
exam, you may be charged with an academic offence.
It’s been a real pleasure teaching you this term. Good luck!
Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14 total
marks 3 4 8 3 5 3 5 2 6 3 6 10 4 8 70
students must hand in this examination booklet at the end
, Page 2 of 22 December 2023 Examinations
CSC 108 H1F
Duration: 3 hours
Question 1. [3 marks]
Complete the following function according to its docstring.
def upper_even(lst: list[str]) -> None:
"""Modify lst so that all strings at an even numbered index in lst are replaced
with an uppercase version of that string. Note: 0 is an even number
>>> lst = ['Abc', 'def', 'hello123', 'hi', 'moo!']
>>> upper_even(lst)
>>> lst
['ABC', 'def', 'HELLO123', 'hi', 'MOO!']
"""
# Hint: Use a string method to get the uppercase version of a string
, December 2023 Examinations Page 3 of 22
CSC 108 H1F
Duration: 3 hours
Question 2. [4 marks]
Write a complete header and docstring for the function below by completing the tasks marked TODO, so that the
docstring correctly describes the function body and the code runs correctly.
# TODO: Complete the parameter names and type contract
def mystery( ) -> :
"""
# TODO: Write a proper docstring description of the function here, e.g. "Return ..."
# TODO: Complete the following precondition with the appropriate parameter
Precondition: len( ) == 1
# TODO: Write two docstring examples with function calls that demonstrate
# different return values for the function
>>> mystery( )
>>> mystery( )
"""
result = ''
for ch in msg.lower():
if ch == ch_to_check.lower():
result = result + ch
return len(result) == count
UNIVERSITY OF TORONTO
Faculty of Arts & Science
December 2023 Examinations
CSC 108 H1F Do not turn this page
until you have received the signal to start.
Duration: 3 hours In the meantime,
please fill out the section below,
Aids Allowed: Provided aid sheet
and carefully read all instructions on this page.
First name (please write as legibly as possible within the boxes)
Last name
Student ID number (9 or 10 digits)
• This final examination consists of 14 questions on 22 pages (including this one), printed on both sides of the paper.
• Answer each question directly on the examination paper, in the space provided. There are several blank pages at
the end for rough work. Do not remove any pages from the exam booklet. If you need more space for one of
your solutions, use one of the blank pages and indicate clearly the part of your work that should be marked.
• We have provided an aid sheet with a list of useful Python function/method descriptions on a separate piece of
paper. Nothing you write on the aid sheet will be marked.
• Remember that, in order to pass the course, you must achieve a grade of at least 40% (28 marks) on this final
examination.
• As a student, you help create a fair and inclusive writing environment. If you possess an unauthorized aid during an
exam, you may be charged with an academic offence.
It’s been a real pleasure teaching you this term. Good luck!
Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14 total
marks 3 4 8 3 5 3 5 2 6 3 6 10 4 8 70
students must hand in this examination booklet at the end
, Page 2 of 22 December 2023 Examinations
CSC 108 H1F
Duration: 3 hours
Question 1. [3 marks]
Complete the following function according to its docstring.
def upper_even(lst: list[str]) -> None:
"""Modify lst so that all strings at an even numbered index in lst are replaced
with an uppercase version of that string. Note: 0 is an even number
>>> lst = ['Abc', 'def', 'hello123', 'hi', 'moo!']
>>> upper_even(lst)
>>> lst
['ABC', 'def', 'HELLO123', 'hi', 'MOO!']
"""
# Hint: Use a string method to get the uppercase version of a string
, December 2023 Examinations Page 3 of 22
CSC 108 H1F
Duration: 3 hours
Question 2. [4 marks]
Write a complete header and docstring for the function below by completing the tasks marked TODO, so that the
docstring correctly describes the function body and the code runs correctly.
# TODO: Complete the parameter names and type contract
def mystery( ) -> :
"""
# TODO: Write a proper docstring description of the function here, e.g. "Return ..."
# TODO: Complete the following precondition with the appropriate parameter
Precondition: len( ) == 1
# TODO: Write two docstring examples with function calls that demonstrate
# different return values for the function
>>> mystery( )
>>> mystery( )
"""
result = ''
for ch in msg.lower():
if ch == ch_to_check.lower():
result = result + ch
return len(result) == count