You are on page 1of 11

MOCK EXAM (FOR PRACTICE

ONLY)
COURSE: ECOR 1041 AB FACILITATOR NAME: GIANA SAMY

It is most beneficial to you to write this mock midterm UNDER EXAM CONDITIONS. This means:
• Complete the exam in 2.5 hour(s).
• Work on your own and attempt every question.
• Keep your notes and textbook closed.
• Do not use your computer, Wing101, PythonTutor or the Python Shell while solving
the questions. You may use a non-programmable calculator.

After the time limit, go back over your work with a different colour or on a separate piece of paper and
try to do the questions you are unsure of. Record your ideas in the margins to remind yourself of what
you were thinking when you take it up at PASS.

The purpose of this mock exam is to give you practice answering questions in a timed setting and to help
you to gauge which aspects of the course content you know well, and which are in need of further
development and review. Use this mock exam as a learning tool in preparing for the actual exam.

Please note:

 Complete the mock exam before attending the take-up session. During the session you can work
with other students to review your work.

 Often, there is not enough time to review the entire exam in the PASS workshop. Decide which
questions you most want to review – the Facilitator may ask students to vote on which
questions they want to discuss in detail.

 Facilitators will not distribute an answer key for mock exams . The Facilitator’s role is to help
students work together to compare and assess the answers they have. If you are not able to
attend the PASS workshop, you can work alone or with others in the class.

 PASS worksheets are designed as a study aid only for use in PASS workshops. Worksheets may
contain errors, intentional or otherwise. It is up to the student to verify the information
contained within by attending the PASS workshop.

Good Luck writing the Mock Exam!!

Take-up Session #1: Monday, October 16th 11:05 am – 12:55 pm (ML 402)

Take-up Session #2: Thursday, October 19th 9:05 am – 10:55 am (TBD)

Contact Information: gianasamy@cmail.carleton.ca


MOCK EXAM (FOR PRACTICE
ONLY)
COURSE: ECOR 1041 AB FACILITATOR NAME: GIANA SAMY

Part A: Multiple Choice

1. How many total function calls are made in the script below (excluding the print statements)?

def function_1(a: int) -> int:


return a
def function_2(b: int) -> bool:
return b > 0
def function_3(c: int) -> None:
return None
b=0
c = 4.0 * b + 1
if (function_1(b) or function_3(c)) and function_3(c) and function_4(a):
print("It works!")
else:
print("Or maybe not")

a) 1 b) 2 c) 3 d) 4 e) The code produces an error.

2. If we ran the following script, which of the following would be the correct output?

def print_line(i: int) -> None:


while (i > 0):
print(i, end="")
i -= 1
for idx in range(1, 5):
print_line(idx)
print()

a) b) c) d) e) None of these
1 1 0 1
12 12 01 21
123 123 012 321
1234 1234 0123 4321
12345 12345 01234
MOCK EXAM (FOR PRACTICE
ONLY)
COURSE: ECOR 1041 AB FACILITATOR NAME: GIANA SAMY

3. Which of the following statements is correct?.

a) The body of a function can have a maximum of one return statement.

b) If a function has a return statement, it needs to be on the right side of an assignment


statement, otherwise we get a ReturnNonBounded error.

c) The return statement should always be at the first thing in the body of the function.

d) None of these statements are correct.

4. Identify the line that will cause an error (either syntax or logic) in the following function body.

def min(y: list, start: int, end: int) -> float:


"""
Return the minimum value in the list y between the indices start and end (inclusive).
"""
curr_smallest = y[end] # Line 1

for i in range(start, end): # Line 2


if y[i] < y[curr_smallest]: # Line 3
curr_smallest = y[i] # Line 4

return curr_smallest

a) Line 1 b) Line 2 c) Line 3 d) Line 4 c) There are no errors.

5. What is the final value bound to x?

def manipulate(x: int) -> int:


if (x < 0):
x *= -1
if (x > 0):
x = x * -1
else:
return x

x = -4
x = manipulate(x)
a) 4 b) -4 c) None d) 0 e) None of these
MOCK EXAM (FOR PRACTICE
ONLY)
COURSE: ECOR 1041 AB FACILITATOR NAME: GIANA SAMY

6. What is printed by the following fragment of code?

def mana(cores: list) -> str:


curr_rank = 'A'
for core in cores:
if curr_rank == 'A':
if core != 'A':
curr_rank = 'A'

else:
if core == 'A':
curr_rank = 'B'
else:
curr_rank = 'B'
return curr_rank

print(mana(['A', 'A', 'A', 'B', 'B', 'A']))


a) A b) B c) AB d) None e) None of these

7. What is the final value bound to x?

x = 'a'
y = 97
y -= y - 1
x += len(x) * x + y * x

a) “a” b) “aa” c) “aaa” d) 96 a’s attached together e) None of these

8. what is the final value bound to x?

def negate(x: float):


if x < 0:
x *= -1
if x >= 0:
return -x

x = -1
x = negate(negate(x) + 1)
a) 0 b) 1 c) -1 d) None e) None of these
MOCK EXAM (FOR PRACTICE
ONLY)
COURSE: ECOR 1041 AB FACILITATOR NAME: GIANA SAMY

9. When performing unit testing on your function you should call the function
from two different files then compare the results.
a) True
b) False

10. Assert statements are used in unit testing to confirm that the expected result is equal to the actual
result.
a) True
b) False

11. What will this code print?


print(“Hi”)
print(“Students”)
a) “Hi” b) “HiStudents” c) “Hi”, “Students” d) “Hi Students”
“Students”

12. What will this code print?


my_list = [1, 2, 5, 3]
x = my_list[-1]
x
a) 1 b) 2 c) 5 d) 3 e) Will result in an error
MOCK EXAM (FOR PRACTICE
ONLY)
COURSE: ECOR 1041 AB FACILITATOR NAME: GIANA SAMY

13. Given the following description, select the best function header.

"""
Return the maximum value out of a, b and c.
"""

a) def x(a: float, b: float, c: float) -> float:


b) def max(nums: List[float]) -> float:
c) def get_max(a: float, b: float, c: float) -> float:
d) def maximum(a: int, b: int, c: int) -> int:
e) def get_max(a: float, b: float, c: float) -> int:
f) These are all poor headers

Part B: Short Answer

1. Here is an incomplete transcript on the Python shell. Write the values that will be displayed
after the final expression before the line is evaluated (assume all the statements they are
applied sequentially, right after one another). If nothing is displayed, write ‘nothing’. If an error
is produced, write ‘error’.

>>> float(int(1.25))

____________________________

>>> lst = [0] * 4

>>> lst += [4]

>>> lst.append(0)

>>> lst

____________________________

>>> lst[2] = lst[len(lst) – 1]

____________________________

>>> lst[5]

____________________________

>>> 8 and not (False and True) or 6 + 2 < 8

____________________________
MOCK EXAM (FOR PRACTICE
ONLY)
COURSE: ECOR 1041 AB FACILITATOR NAME: GIANA SAMY

>>> x = 10

>>> y = 1.0

>>> z += x

>>> y = x / 5 * (z % y)

____________________________

>>> tax = 1.13(50)

____________________________

>>> strA = ‘Hi ’

>>> strB = ‘There’ * 2

>>> strA + strB

____________________________

>>> a = “There are ” + (4 + 2) + “ moons on Saturn!”

____________________________

2. Convert this unsigned binary integer 100001012 to decimal.


MOCK EXAM (FOR PRACTICE
ONLY)
COURSE: ECOR 1041 AB FACILITATOR NAME: GIANA SAMY

3. Convert this signed magnitude binary integer 110100112 to


decimal.

4. Convert this floating point binary number 0.10112 to decimal.

5. Convert this unsigned decimal number 3510 to binary.


MOCK EXAM (FOR PRACTICE
ONLY)
COURSE: ECOR 1041 AB FACILITATOR NAME: GIANA SAMY

Part C: Long Answer

1. Write a function named name_list that prompts the user to enter one name at a time, then when
the user enters “Stop” it returns a list of all the names entered.

For example:

Note: blue is the user’s input

>>>name_list()

…Enter a name: Giana

…Enter a name: Ben

…Enter a name: Stop

…[Giana, Ben]
MOCK EXAM (FOR PRACTICE
ONLY)
COURSE: ECOR 1041 AB FACILITATOR NAME: GIANA SAMY

2. Complete the body of the function following the instructions in the


provided docString.

• No list functions may be used except for len() and range().

• Your solution must contain a for-loop

def loop_function (names:list, length:int) -> list:

“””Return a list of booleans that indicates whether each individual name exceeds the given length.

Precondition: length > 0.

>>> loop function(["Jo", "Sue", "Pierre"], 3)


[False, False, True]

>>> loop_function(["Jo", "Sue", "Pierre"], 2)


[False, True, True]

“””
MOCK EXAM (FOR PRACTICE
ONLY)
COURSE: ECOR 1041 AB FACILITATOR NAME: GIANA SAMY

Bonus questions:

3. Write a function called unique that will accept a list of integers, which may contain duplicate values,
and returns a list with the duplicates removed. Your function may not use any built-in python
functions and must follow the FDR. If you choose, you may implement a helper function that your
unique function can call.

Note: The order of the values that appear in the list without duplicates is irrelevant, as long as all
of them appear.

Here’s an example:

"""
>>> unique([1, 2, 3, 5, 2, 4, 4, 1])
>>> [1, 2, 3, 5, 4]
"""

You might also like