← Python

OOP – Practical Application

A class models a real-world entity by combining related attributes and methods in one structure

What it does: __init__ runs automatically when a new object is created. Methods can read and modify the object's own attributes via self. OOP keeps the data (balance) and the operations (deposit, withdraw) in one place. __init__ stores the initial state — every account needs an owner and a starting balance. Good OOP enforces its own rules — the withdraw method guards against going negative. deposit() modifies the object's own balance using self.balance += amount. Each BankAccount() call creates a separate account with its own balance. Encapsulation keeps data and the code that manipulates it together in one class.

Common mistakes: No balance check could go negative. Add validation. Must use self.balance balance alone is undefined here.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Why use OOP for a bank account?
Groups related data and behavior togetherIt's faster
Matches
❌ def __init__(name):
Error: Missing self in __init__
Applying
Meanings
Term
Encapsulation
Meaning
Bundling data and methods that operate on it together in a class.
Practice
class BankAccount:
Testing
Gaps
self. += amount
Check Answer
Spots
2 def withdraw(self, amount):
3 self.balance -= amount

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Space Turtle' badge — Speed in Zero-G, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Why use OOP for a bank account?
A. Groups related data and behavior together ✓
B. It's faster
OOP keeps the data (balance) and the operations (deposit, withdraw) in one place
2. What should __init__ set for a BankAccount?
A. Only the class name
B. owner and balance ✓
__init__ stores the initial state — every account needs an owner and a starting balance
3. Why check balance before withdrawing?
A. To prevent overdraft ✓
B. Python requires it
Good OOP enforces its own rules — the withdraw method guards against going negative
4. acc.deposit(50) what should this do?
A. Create a new account
B. Add 50 to self.balance ✓
deposit() modifies the object's own balance using self.balance += amount
5. Can one class have many objects?
A. Yes each with their own data ✓
B. No only one
Each BankAccount() call creates a separate account with its own balance

Match the Pairs

def __init__(name): Error: Missing self in __init__
acc.balance() Error: balance is an attribute, not a method
def __init__(self, name): Valid: Constructor with self and a parameter
self.balance += amount Ok: Update an instance attribute in a method
round(3.14159, 2) Output: 3.14
abs(-7) Output: 7

Key Term

Encapsulation
Bundling data and methods that operate on it together in a class.~~State

Fill in the Blanks

1. class BankAccount: def deposit(self, amount): self.balance += amount
2. class TodoList: def add(self, task): self.tasks.append(task)
3. class BankAccount: def withdraw(self, amount): if amount <= self.balance: self.balance -= amount
4. acc = BankAccount('Alice', 100) acc.deposit(50)
5. class Score: def __init__(self): self.points = 0

Spot the Error

Question 1
A class BankAccount:
B def withdraw(self, amount):
C self.balance -= amount
Line C — No balance check could go negative. Add validation.
Question 2
A class BankAccount:
B def deposit(self, amount):
C balance += amount
Line C — Must use self.balance balance alone is undefined here
Question 3
A class TodoList:
B def __init__(self):
C tasks = []
D def add(self, task):
E self.tasks.append(task)
Line C — tasks = [] is a local variable. Use self.tasks = [] to store on object.
Question 4
A class BankAccount:
B def deposit(amount):
C self.balance += amount
Line B — Missing self as first parameter
Question 5
A class BankAccount:
B def __init__(self):
C self.balance = 0
D def deposit(self, amount):
E self.balance += amount
Line E — No validation negative deposits shouldn't be allowed
For Teachers

Create a free class, add this module to a journey, and track who's stuck.

Create a free teacher account →

No credit card. No setup fee. Make a class and invite students in under three minutes.

For Students

Practice this topic interactively, track progress, and unlock badges.

Start Learning Free →

Have a class code?