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 | |
|---|---|---|
| 1obj.__balance | AError: Use snake_case: get_balance | |
| 2def getBalance(self): | BError: Double underscore triggers name mangling | |
| 3self._balance | COk: Getter method to access private data | |
| 4def get_balance(self): | DOutput: 1 | |
| 510 // 3 | EOutput: 3 | |
| 610 % 3 | FValid: Single underscore signals internal use |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
_variable — Convention for internal use - don't access directly from outside the class.~~__variableclass Account:
def __init__(self, bal):
self._balance = balclass Account:
def get_balance(self):
return self._balanceclass Account:
def deposit(self, amount):
if amount > 0:
self._balance += amountclass Secret:
def __init__(self, val):
self.__val = valacc = Account(100)
print(acc.get_balance( ))