Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
This Methods with parameters and return values (Python) worksheet is part of the ACARA Digital Technologies Years 9–10 — Modular and Object-Oriented Programming (Python) journey. Print it as a booklet?
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 | |
|---|---|---|
| 1def deposit(self, amount): | AA method that takes an extra parameter, amount, after self so the caller can pass in a value to use | |
| 2return self.balance * 0.05 | BThe method is missing self as its first parameter, so it cannot access self.balance and the call will fail with a TypeError. | |
| 3A method changes an attribute using the value passed in as a parameter | CThe method uses print instead of return, so it only displays the value and the caller gets None back. | |
| 4A method checks a value with an if statement before it changes an attribute | Dself.balance += amount | |
| 5def deposit(amount): self.balance += amount | Eif amount > 0: self.balance += amount | |
| 6def get_interest(self): print(self.balance * 0.05) | FSends a calculated value back to the code that called the method |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
def deposit(self, amount): — A method can take extra parameters after self, like amount, and use return to send a value back to the code that called it. def deposit(self, amount):
self.balance += amount def deposit(self, amount):
self.balance += amountdef area(self):
return self.width * self.height def withdraw(self, amount):
if amount <= self.balance:
self.balance -= amountacc = Account(100)
acc.deposit(50)
print(acc.balance)