Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1class Student: def __init__(self, name, year): | Aclass Member: def __init__(self, name, cardNo): | |
| 2account.deposit(50) | BThe calling code repeats the detail of how the total is calculated instead of using a method like cart.calculate_total() that hides it. | |
| 3Abstraction: the same real thing (a person) can be modelled with different attributes for different purposes, such as a library app. | Cdef calculate_total(self): return sum(self._prices) | |
| 4Abstraction: a method hides how a task is done so other code only needs to know what it does. | DAbstraction: the Student class keeps only the attributes a school app needs (name, year level) and leaves out details like eye colour or favourite food. | |
| 5class Student: def __init__(self, name, eyeColour, pet, shoeSize, year): | EAbstraction: the deposit() method hides the complex steps (checking, updating, logging) so the caller just asks for the result. | |
| 6total = 0 for p in cart._prices: total += p print(total) | FThe class includes irrelevant attributes (eyeColour, pet, shoeSize) for a school app. Abstraction means keeping only the attributes that matter for the purpose, such as name and year. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
abstraction — Modelling only the attributes and methods that matter for a purpose and hiding the rest of the detail, such as a Student class that keeps just the data a school app needs.class Student:
def show(self):
return self.nameclass Car:
def start(self):
self.check()class Kettle:
def boil(self):
self.heat()class Patient:
def info(self):
return self.allergydef area(w, h):
return w * h
print(area(3, 4))