Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the primary responsibility of the User class in an expense management system?
The User class represents an individual who can participate in groups and record or share expenses. It typically holds user details like name, email, and unique ID.
Click to reveal answer
beginner
How does the Group class help in managing expenses?
The Group class organizes multiple users into a collection where expenses can be shared and tracked collectively. It manages group members and their shared expenses.
Click to reveal answer
beginner
What key attributes should the Expense class have?
The Expense class should include attributes like amount, description, date, payer (User), and participants (Users who share the expense).
Click to reveal answer
intermediate
Why is it important for the Expense class to track participants separately from the payer?
Tracking participants separately allows the system to split the expense fairly or by custom shares among users, while the payer is the one who initially paid the amount.
Click to reveal answer
intermediate
How can the Group class maintain scalability when handling many users and expenses?
By using efficient data structures like hash maps for quick user lookup, and by separating expense records to avoid large monolithic objects, the Group class can scale well.
Click to reveal answer
Which class should store the list of users who share a particular expense?
AExpense
BUser
CGroup
DNone of the above
✗ Incorrect
The Expense class stores participants who share the cost of that expense.
In an expense system, who is responsible for paying the amount initially?
AGroup
BExpense
CUser (payer)
DAll participants
✗ Incorrect
The User who pays the amount is called the payer.
What does the Group class primarily manage?
AExpense splitting logic
BCollection of users and their shared expenses
CIndividual user details
DPayment processing
✗ Incorrect
Group manages users and the expenses shared among them.
Which attribute is NOT typically part of the Expense class?
AGroup name
BDate
CAmount
DDescription
✗ Incorrect
Group name belongs to the Group class, not Expense.
Why separate payer and participants in an expense?
ATo avoid duplicate users
BTo reduce storage space
CTo speed up calculations
DTo identify who paid and who owes money
✗ Incorrect
Separating payer and participants clarifies payment and debt responsibilities.
Describe the roles and key attributes of User, Group, and Expense classes in an expense sharing system.
Think about who pays, who shares, and how groups organize users.
You got /3 concepts.
Explain why it is important to track both the payer and participants separately in the Expense class.
Consider a dinner bill paid by one but shared by many.
You got /3 concepts.
Practice
(1/5)
1. Which class is primarily responsible for storing information about individual people in a shared expense system?
easy
A. Payment
B. User
C. Expense
D. Group
Solution
Step 1: Understand the role of each class
User class represents individual people, Group holds multiple users, Expense tracks costs.
Step 2: Identify which class stores individual info
User class stores personal details like name and ID for each person.
Final Answer:
User -> Option B
Quick Check:
User = Individual person [OK]
Hint: User class = individual person info [OK]
Common Mistakes:
Confusing Group with User
Thinking Expense stores user details
Assuming Payment is a class here
2. Which of the following is the correct way to define a Group class that holds multiple User objects in Python?
easy
A. class Group:
def __init__(self):
self.users = []
B. class Group:
def __init__(self):
self.user = {}
C. class Group:
def __init__(self):
self.expenses = []
D. class Group:
def __init__(self):
self.members = None
Solution
Step 1: Identify correct attribute for multiple users
A list is suitable to hold multiple User objects, so self.users = [] is correct.
Step 2: Check other options for correctness
class Group:
def __init__(self):
self.user = {} uses a dict named user which is not typical for holding users; class Group:
def __init__(self):
self.expenses = [] uses expenses which belongs to Expense class; class Group:
def __init__(self):
self.members = None sets members to None which is not a collection.
Final Answer:
class Group:
def __init__(self):
self.users = [] -> Option A
Quick Check:
Group holds list of users = self.users = [] [OK]
Hint: Group holds list of users with self.users = [] [OK]
Common Mistakes:
Using dict instead of list for users
Confusing expenses with users
Initializing members as None instead of a list
3. Given the following code snippet, what will be the output?
A. Using integer division (//) may lose cents in split
B. split_between should be a dictionary, not a list
C. paid_by should be a list, not a single user
D. amount should be a string, not a number
Solution
Step 1: Analyze the division operator used
The method uses integer division (//) which truncates decimals.
Step 2: Understand impact on money split
Using // can lose fractional cents, causing inaccurate splits.
Final Answer:
Using integer division (//) may lose cents in split -> Option A
Quick Check:
Integer division truncates decimals, causing loss [OK]
Hint: Use float division (/) for accurate money splits [OK]
Common Mistakes:
Ignoring decimal loss from integer division
Confusing data types for paid_by or split_between
Thinking amount should be string
5. You want to design a system where multiple users in a group can add expenses, and the system automatically calculates how much each user owes or is owed. Which design approach best supports scalability and clear responsibility?
hard
A. Make User class handle all expense calculations and group management to centralize logic
B. Use only a single Expense class that stores all users and groups inside it to simplify design
C. Create User, Group, and Expense classes where Group manages users and expenses; Expense tracks amount and split; User tracks individual balances updated by Group
D. Store all data in a flat file and calculate splits manually each time without classes
Solution
Step 1: Identify responsibilities for each class
User holds personal info and balances, Group manages users and expenses, Expense tracks costs and splits.
Step 2: Evaluate design for scalability and clarity
Create User, Group, and Expense classes where Group manages users and expenses; Expense tracks amount and split; User tracks individual balances updated by Group cleanly separates concerns, making it easier to maintain and scale.
Final Answer:
Create User, Group, and Expense classes where Group manages users and expenses; Expense tracks amount and split; User tracks individual balances updated by Group -> Option C
Quick Check:
Clear class roles = scalable design [OK]
Hint: Separate concerns: User, Group, Expense each handle distinct roles [OK]