Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the transaction list.
LLD
class TransactionHistory: def __init__(self): self.transactions = [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a dictionary {} instead of a list.
Initializing with None or 0.
✗ Incorrect
We use an empty list [] to store transactions in order.
2fill in blank
mediumComplete the code to add a transaction to the history.
LLD
def add_transaction(self, transaction): self.transactions.[1](transaction)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove or pop which delete items.
Using insert without specifying index.
✗ Incorrect
We use append to add a new transaction at the end of the list.
3fill in blank
hardFix the error in the method to get the last transaction.
LLD
def get_last_transaction(self): if not self.transactions: return None return self.transactions[[1]]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 returns the first transaction.
Using len(self.transactions) causes index error.
✗ Incorrect
Index -1 accesses the last item in a list in Python.
4fill in blank
hardFill both blanks to filter transactions by minimum amount.
LLD
def filter_transactions(self, min_amount): return [t for t in self.transactions if t.[1] >= [2]]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing wrong attributes like date or status.
Using wrong variable names.
✗ Incorrect
We compare each transaction's amount to the min_amount parameter.
5fill in blank
hardFill all three blanks to create a dictionary of transaction IDs to amounts for completed transactions.
LLD
def get_completed_transactions(self): return {t.[1]: t.[2] for t in self.transactions if t.[3] == 'completed'}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys or values in the dictionary.
Filtering by wrong attributes.
✗ Incorrect
We map each transaction's transaction_id to its amount only if its status is 'completed'.