Expressions, Types and Memory · Multiple choice · 1 mark
What is printed by the following code?
print('A', 'B', sep='', end='')
print('C', 'D', end='!')ABC D!
AB on one line, then C D! on the next line
ABCD!
A B C D!
ABC!D!
Answer: (A)
ABC D!. The first call prints AB with no newline; the second uses the default sep (a space) between C and D, then ends with !.
Functions and the Design Recipe · Write code · 2 marks
Complete the body of hypotenuse according to its docstring. You must call square.
import math
def square(x: float) -> float:
"""Return x squared.
>>> square(3.0)
9.0
"""
return x * x
def hypotenuse(a: float, b: float) -> float:
"""Return the length of the hypotenuse of a right triangle whose
other two sides have lengths a and b.
>>> hypotenuse(3.0, 4.0)
5.0
>>> hypotenuse(5.0, 12.0)
13.0
""" return math.sqrt(square(a) + square(b))Using sqrt without the math. prefix raises a NameError.
For and While Loops · Predict the output · 2 marks
Write the output of the following code. If the code raises an error, write ERROR and stop.
a = 0
b = 10
while a < b:
a = a + 3
b = b - 1
print(a, b)
print(a + b)3 9
6 8
9 7
16Nested Lists and Loops · Predict the output · 2 marks
Write the output of the code below. If the code raises an error, write ERROR and stop.
line = 'Ana,82,90;Ben,75,64;Cy,93,88'
records = []
for part in line.split(';'):
records.append(part.split(','))
print(len(records))
print(records[1])
print(records[2][1] + records[0][2])
print(int(records[1][2]) + 1)3
['Ben', '75', '64']
9390
65The marks are still strings, so + concatenates them until int converts one.
Testing and Debugging · Short answer · 3 marks
A student wrote this pytest test.
def test_empty() -> None:
"""Test count_negatives on an empty list."""
actual = count_negatives([])
expected = 0
actual == expectedThe test passes even when count_negatives([]) returns 5. Why? [1]
Exactly when does this test fail? [1]
Fix the test. [1]
The last line only evaluates a Boolean expression and throws the result away; nothing checks it.
Only when the call count_negatives([]) raises an error.
Change the last line to assert actual == expected.
Introduction to Computer Science and Programming · York University (York, YorkU, York U) · also written EECS1015
Make a free, printable EECS 1015 practice exam: choose the topics, the length and the difficulty above, and get an exam-style PDF with a full answer key. Each paper draws on 800 original questions and skips the ones you have already seen.
Start with the past exams and tests your instructor or the York library shares: they show what your course actually asks. Most courses only have a few, so once you have worked through them, make fresh EECS 1015 practice exams here on the same topics, with full answer keys, as many as you need. The questions here are original, not copies of past exams.
questionbank.dev is independent and not affiliated with York University. Course codes only say which topics a paper covers; papers are original practice material, not past or upcoming exams.