Project 11 of 20, for Caitlin
Bank Account System
Savings accounts for the class festival fund, each one a Python object that keeps its own balance and says no for itself.
Sign up free to open itLog in
Act 2 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- CaitlinHalf the class are going to a festival in the summer, and I'm the one keeping the savings.
- CaitlinLast week somebody wrote minus five pounds on my savings sheet and then took it out again.
- CaitlinAn account should know its own balance, and nobody should take out more than they've put in.
- PaulThen each account should know that about itself and be able to say no on its own.
Write a class Account in bank.py. Money is kept in whole pence, so 2000 is £20.
Account(holder, number)opens an account: the holder's name, the account number, abalanceof 0, andhistory, an empty list.deposit(pence)pays money in: it adds to the balance and appends the amount tohistory. An amount that isn't more than 0 raises aValueErrorand changes nothing.withdraw(pence)takes money out, appends it tohistoryas a negative number, and returnsTrue. More than the balance changes nothing and returnsFalse: the festival fund doesn't lend. An amount that isn't more than 0 raises aValueError.str(account)gives one line, the balance in pounds:Account 1042, Aaesha: £12.50.
Account 1042, Aaesha: £12.50 False [2000, -750]
What you learn
What's in it
- A pattern for things
- Two accounts from one pattern
- Setting up each new one
- Never set
- What an account can do
- The class or the account
- Methods and self
- In plain words
- How an account introduces itself
- How Paul would do it
- Fix Caitlin's version
- Make the account
- Ship it