Sample APS106H1 questions
  1. Expressions, Types and Memory · Multiple choice · 2 marks

    Variables x and y refer to two different ints. Which code fragments swap their values? Circle ALL that apply.

    1. x = y then y = x

    2. temp = x then x = y then y = temp

    3. x, y = y, x

    4. temp = y then y = x then x = temp

    5. temp = x then y = x then x = temp

    6. x = x + y then y = x - y then x = x - y

    Show solution

    Answer: (B, C, D, F)

    The second, third, fourth and sixth fragments. The first sets both to the old y; the fifth sets both to the old x. The last one works for numbers: after line 1 x holds the sum, so x - y is the old x and the new x - y is the old y.

  2. Booleans and Conditionals · Write code · 2 marks

    Complete the function body according to its docstring.

    def triangle_type(a: int, b: int, c: int) -> str:
        """Return 'equilateral' if the side lengths a, b and c are all
        equal, 'isosceles' if exactly two of them are equal, and
        'scalene' if no two of them are equal.
    
        Precondition: a, b and c are the sides of a valid triangle.
    
        >>> triangle_type(3, 3, 3)
        'equilateral'
        >>> triangle_type(5, 3, 5)
        'isosceles'
        >>> triangle_type(3, 4, 5)
        'scalene'
        """
    Show solution
        if a == b == c:
            return 'equilateral'
        elif a == b or b == c or a == c:
            return 'isosceles'
        else:
            return 'scalene'

    Checking the equilateral case first matters: an equilateral triangle also satisfies the isosceles condition. Forgetting the a == c comparison is a common mistake.

  3. Lists, Mutability and Aliasing · Write code · 3 marks

    Complete the function body according to its docstring.

    def above_average(marks: list[int]) -> list[int]:
        """Return a new list of the items in marks that are strictly
        greater than the average of marks, in their original order.
    
        Precondition: len(marks) > 0
    
        >>> above_average([65, 80, 72, 91])
        [80, 91]
        >>> above_average([50, 50])
        []
        """
    Show solution
        total = 0
        for mark in marks:
            total = total + mark
        average = total / len(marks)
    
        result = []
        for mark in marks:
            if mark > average:
                result.append(mark)
        return result

    The average must be computed in a first loop, before any item is compared.

  4. Tuples and Dictionaries · Write code · 3 marks

    Complete the function body according to its docstring. You may not use sum.

    def student_averages(grades: dict[str, dict[str, int]]
                         ) -> dict[str, float]:
        """Return a new dictionary that maps each student in grades to
        the average of that student's marks.
    
        grades maps each student to a dictionary that maps course codes
        to the student's mark in that course.
    
        Precondition: every inner dictionary is non-empty.
    
        >>> marks = {'Ana': {'CSC108': 80, 'MAT137': 70},
        ...          'Raj': {'CSC108': 91}}
        >>> student_averages(marks) == {'Ana': 75.0, 'Raj': 91.0}
        True
        """
    Show solution
        result = {}
        for student in grades:
            total = 0
            for course in grades[student]:
                total = total + grades[student][course]
            result[student] = total / len(grades[student])
        return result

    Common mistake: initializing total = 0 outside the outer loop, so marks carry over from one student to the next.

  5. Classes and Objects · Multiple choice · 1 mark

    Class Thermometer has a method to_fahrenheit whose only parameter is self, and t refers to a Thermometer object. Which of these expressions correctly call the method on t? Circle ALL that apply.

    1. t.to_fahrenheit()

    2. Thermometer.to_fahrenheit(t)

    3. to_fahrenheit(t)

    4. t.to_fahrenheit(t)

    5. Thermometer.to_fahrenheit()

    Show solution

    Answer: (A, B)

    t.to_fahrenheit() is shorthand for Thermometer.to_fahrenheit(t). The others raise errors: the method is not a global function, and self must be given exactly once.

About APS106H1 practice exams

APS106H1 practice exams

Fundamentals of Computer Programming · University of Toronto (UofT, U of T, UToronto) · also written APS106, APS 106

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

Looking for APS106H1 past exams?

Start with the past exams and tests your instructor or the UofT library shares: they show what your course actually asks. Most courses only have a few, so once you have worked through them, make fresh APS106H1 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
  • Tuples and Dictionaries · 100 questions
  • Reading and Writing Files · 100 questions
  • Searching, Sorting and Complexity · 100 questions
  • Classes and Objects · 100 questions

More UofT courses

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