Skip to content
KALANBLON
Show contents

Chapter 3 of 6 · 10 min

Quiz: objects

Classes, objects, dataclasses and inheritance: let's check that you can build your own objects. You need 70 % correct answers, and every answer is explained.

Quiz

5 questions · pass mark: 70%

  1. 1.What does this program display?

    One answer

    class Counter:
        def __init__(self):
            self.n = 0
    
        def plus(self):
            self.n += 1
    
    a = Counter()
    b = Counter()
    a.plus()
    a.plus()
    b.plus()
    print(a.n, b.n)
  2. 2.In a method, what does self refer to?

    One answer

  3. 3.What does @dataclass generate from the annotated attributes? (several answers)

    Several answers possible

  4. 4.Complete to call the parent class's constructor.

    Complete the code

    class Circle(Shape):
        def __init__(self, radius):
            _______().__init__("Circle")
            self.radius = radius
  5. 5.Why do two students share the same list of grades?

    One answer

    class Student:
        def __init__(self, name, grades=[]):
            self.grades = grades

Your progress is saved on this device. Create a free account to keep your progress on all your devices.