Object-oriented programming: IB Computer Science practice
Classes, objects and inheritance. 5 questions in the style of the IB Computer Science exam.
Sample questions
What does this program print?
class BankAccount:
def __init__(self, owner, balance=0):
self.owner = owner
self.balance = balance
def deposit(self, amount):
self.balance += amount
def withdraw(self, amount):
if amount > self.balance:
return False
self.balance -= amount
return True
acc = BankAccount("Mei", 50)
acc.deposit(25)
print(acc.withdraw(100))
print(acc.withdraw(30))
print(acc.owner, acc.balance)