Money Transfer
Python
30 pts
Money Transfer
Build a BankAccount class with __init__(self, owner, balance=0) and three methods:
deposit(amount)— adds the amount to the balance.withdraw(amount)— if the balance is big enough, subtracts the amount and returnsTrue; otherwise changes nothing and returnsFalse.transfer(other, amount)— moves money to the accountother. It must useself.withdraw()andother.deposit(), and returnTrueif it worked orFalseif there was not enough money.
The code at the bottom is ready. Expected output:
True False Selam: 700 Nakfa Abel: 500 Nakfa
Checklist
- Define a class
BankAccountwith anowner, abalancethat defaults to 0, and adeposit()method. - Add
withdraw(): it subtracts the money and returnsTrueonly when the balance is big enough; otherwise it returnsFalse. - Add
transfer(other, amount)that usesself.withdraw()andother.deposit()and returnsTrueorFalse. - Run the code at the bottom.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
