Paul's Python CoursePPC

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.

About an hour and a half, in 14 steps.

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, a balance of 0, and history, an empty list.
  • deposit(pence) pays money in: it adds to the balance and appends the amount to history. An amount that isn't more than 0 raises a ValueError and changes nothing.
  • withdraw(pence) takes money out, appends it to history as a negative number, and returns True. More than the balance changes nothing and returns False: the festival fund doesn't lend. An amount that isn't more than 0 raises a ValueError.
  • str(account) gives one line, the balance in pounds: Account 1042, Aaesha: £12.50.
What it prints
Account 1042, Aaesha: £12.50
False
[2000, -750]

What you learn

What's in it

  1. A pattern for things
  2. Two accounts from one pattern
  3. Setting up each new one
  4. Never set
  5. What an account can do
  6. The class or the account
  7. Methods and self
  8. In plain words
  9. How an account introduces itself
  10. How Paul would do it
  11. Fix Caitlin's version
  12. Make the account
  13. Ship it