Sample COMPSCI 1MD3 questions
  1. Expressions, Types and Memory · Multiple choice · 1 mark

    What is printed by the following line?

    print(max(3, 7.0, 5), min(2.0, 2))
    1. 7 2

    2. 7.0 2

    3. 7 2.0

    4. ERROR, because int and float values cannot be compared.

    5. 7.0 2.0

    Show solution

    Answer: (E)

    (E). max and min return one of their arguments unchanged, so the largest is the float 7.0. For min(2.0, 2) the two values are equal, and the first one, 2.0, is returned.

  2. Booleans and Conditionals · Multiple choice · 1 mark

    Assume a, b and c refer to Boolean values. Python evaluates the expression not a or b and c in the same way as which of the following?

    1. (not a) or (b and c)

    2. not (a or b) and c

    3. ((not a) or b) and c

    4. not (a or (b and c))

    Show solution

    Answer: (A)

    (A). Among the Boolean operators, not binds most tightly, then and, then or.

  3. For and While Loops · Predict the output · 3 marks

    Write the output of each code fragment. If the code raises an error, write ERROR and stop.

    1. n = 3
      for i in range(n):
          n = n + 1
          print(i, n)
      print(n)

      [2]

    2. for i in range(3):
          print(i, end=' ')
          i = i * 10
          print(i)

      [1]

    Show solution

    (a)

    0 4
    1 5
    2 6
    6

    (b)

    0 0
    1 10
    2 20

    range(n) is evaluated once, before the first iteration, and each iteration rebinds i to the next value from the range, whatever the body did to n or i.

  4. Nested 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.

    for i in range(1, 5):
        line = ''
        for j in range(i, 5):
            line = line + str(j)
        print(line)
    print(i, j)
    Show solution
    1234
    234
    34
    4
    4 4

    The inner loop starts at i, so each line is one digit shorter. After the loops, i and j keep their last values.

  5. Testing and Debugging · Multiple choice · 1 mark

    def smallest(nums: list[int]) -> int:
        """Return the smallest item in nums.
    
        Precondition: len(nums) > 0
        """

    The test suite already has the arguments [5], [1, 8, 3] and [6, 2, 9]. Which one additional argument adds the most value to the suite?

    1. [4]

    2. []

    3. [9, 7, 3]

    4. [2, 8, 3]

    Show solution

    Answer: (C)

    (C). The suite has the smallest item first and in the middle, but never last. [] violates the precondition, and (A) and (D) repeat categories already tested.

About COMPSCI 1MD3 practice exams

COMPSCI 1MD3 practice exams

Introduction to Programming · McMaster University (McMaster, Mac, MacU) · also written COMPSCI1MD3

Make a free, printable COMPSCI 1MD3 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 1,000 original questions and skips the ones you have already seen.

Looking for COMPSCI 1MD3 past exams?

Start with the past exams and tests your instructor or the McMaster library shares: they show what your course actually asks. Most courses only have a few, so once you have worked through them, make fresh COMPSCI 1MD3 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.

Topics covered

  • Expressions, Types and Memory · 100 questions
  • Functions and the Design Recipe · 100 questions
  • Booleans and Conditionals · 100 questions
  • Strings · 100 questions
  • For and While Loops · 100 questions
  • Lists, Mutability and Aliasing · 100 questions
  • Nested Lists and Loops · 100 questions
  • Reading and Writing Files · 100 questions
  • Tuples and Dictionaries · 100 questions
  • Testing and Debugging · 100 questions

More McMaster courses

questionbank.dev is independent and not affiliated with McMaster University. Course codes only say which topics a paper covers; papers are original practice material, not past or upcoming exams.