Bank

class bank.Bank(name)[source]

A Bank has many accounts.

Parameters

name (str) – The bank’s name.

Example:

>>> from bank import Bank
>>> bank = Bank("Supersafe Ltd")
Bank Supersafe Ltd            | Open for business.
>>> bank.add_account("Heihei")
Bank Supersafe Ltd            | added an account named Heihei.
>>> bank.deposit("Heihei", 400)
Account Heihei                | Deposited 400. New balance is 400.
Bank Supersafe Ltd            | Deposit of 400 to Heihei accepted.
add_account(account_name)[source]

Adds a new account to the bank if allowed.

Returns

Whether the request succeeded.

Return type

bool

account_exists(account_name)[source]

Checks whether an account exists.

Parameters

account_name (str) – The account name.

Returns

Whether the account exists.

Return type

bool

deposit(account_name, amount)[source]

Accepts a deposit into an account.

Parameters
  • account_name (str) – The account name.

  • amount (float) – The amount to deposit.

Returns

Whether the deposit succeeded.

Return type

bool

withdraw(account_name, amount)[source]

Withdraws money from an account if possible.

Parameters
  • account_name (str) – The account name.

  • amount (float) – The amount to withdraw.

Returns

Whether the withdrawal succeeded.

Return type

bool

check_balance(account_name)[source]

Checks the balance of an account if one exists

Parameters

account_name (str) – The account name.

Returns

The balance of the account or None if the account doesn’t exist.

report(activity)[source]

Prints out a successful activity.

Parameters

activity (str) – A description of what happened.

bank.transfer(source_account_name, destination_account_name, amount)

NOTE: THIS METHOD IS NOT YET IMPLEMENTED!

Moves the amount from a source account to a destination account name if there are accounts with both names in this Bank and if there are sufficient funds in the source account. Reports to the user what happened.

Parameters
  • source_account_name (str) – Name of the source account.

  • destination_account_name (str) – Name of the destination account.

  • amount (float) – How much money to transfer.

Returns

Whether the transfer succeeded.

Return type

bool