Bank Account System v2 — Adding SQLite Persistence
Remember the Bank Account System from Week 5? Every time you quit the program, all your accounts vanished. This week you'll fix that.
You'll add a SQLite database layer to the existing codebase so that accounts and every
transaction are stored permanently in a file called bank.db. When the program starts, it reads
the database and picks up exactly where it left off.
CREATE TABLE, INSERT, UPDATE,
SELECT, and WHERE clauses
The Week 5 OOP layer (Account classes, Bank class, menu) is already written in the scaffolding file. Your only job is to fill in the database pieces.
Click below to download all the files you need to get started:
By completing this assignment, you'll be able to:
sqlite3 moduleCREATE TABLE IF NOT EXISTS? placeholdersSELECT, WHERE, ORDER BY, and LIMIT
You will create two tables in bank.db:
| Column | Type | Notes |
|---|---|---|
account_number |
TEXT | PRIMARY KEY (e.g. "ACC-4821") |
owner_name |
TEXT | NOT NULL |
account_type |
TEXT | "checking" or "savings" |
balance |
REAL | DEFAULT 0.0 |
withdrawal_count |
INTEGER | DEFAULT 0 (used by SavingsAccount) |
created_at |
TEXT | Timestamp string |
| Column | Type | Notes |
|---|---|---|
id |
INTEGER | PRIMARY KEY AUTOINCREMENT |
account_number |
TEXT | FOREIGN KEY → accounts |
type |
TEXT | "deposit", "withdrawal", "fee", "interest" |
amount |
REAL | NOT NULL |
balance_after |
REAL | Balance immediately after this transaction |
timestamp |
TEXT | Timestamp string |
Building on the Week 5 program, your updated system must:
bank.db automatically on first runtransactions tableThe scaffolding file has 17 TODO markers. Work through them in this order:
DATABASE_FILE constantDatabase class method by method; after each
one, add a quick test at the bottom of the file to confirm it works
Bank.__init__ and
create_account() to use the database; restart the program and verify accounts reload
update_balance() and
save_transaction() in the menu; implement the transaction history view
bank_v2.py — your starting point with the Week 5 OOP layer complete and 17 database TODO
markers
cheat_sheet.py — SQLite reference patterns: connecting, creating tables, inserting,
querying, updating, and more
import sqlite3 and you're ready to go.
bank.db and browse your tables like a spreadsheet while you develop. This makes
debugging much faster.
commit() after writes. Without a commit, inserts and updates are rolled
back when the connection closes and nothing is saved.
? placeholders, never f-strings in SQL. Formatting user input directly
into a SQL string is a security vulnerability called SQL injection.
bank.db to start fresh. If your table schema gets into a bad state
during development, just delete the file and let the program recreate it.
=== Welcome to First National Bank === Loaded 2 account(s) from database. 1. Open new account 2. Deposit funds 3. Withdraw funds 4. Check balance 5. View transaction history 6. List all accounts 7. Apply monthly fee / interest 8. Quit Choose an option: 5 Account number: ACC-4821 Transaction history for ACC-4821: Timestamp Type Amount Balance ---------------------------------------------------------- 2026-02-28 14:01:00 interest $10.00 $510.00 2026-02-28 14:00:00 deposit $500.00 $500.00