Complete the code to initialize the net balance for each person.
net_balance = {person: 0 for person in [1]We initialize net_balance for each person in the list people.
Complete the code to update net balances after each transaction.
net_balance[debtor] [1]= amount net_balance[creditor] [1]= -amount
Debtor's balance decreases by amount, creditor's balance increases by amount, so debtor subtracts amount and creditor adds amount (negative subtract equals add).
Fix the error in the code to find the person with maximum credit.
max_credit_person = max(net_balance, key=lambda x: net_balance[[1]])
The lambda function parameter x is used to access net_balance[x].
Fill both blanks to correctly update balances after settling debts.
settle_amount = min(net_balance[[1]], -net_balance[[2]]) net_balance[[1]] -= settle_amount net_balance[[2]] += settle_amount
We settle debts between the person with max credit and max debit.
Fill all three blanks to create the final simplified debts record.
if settle_amount > 0: simplified_debts.append(([1], [2], [3]))
The simplified debt is from debtor to creditor with the settled amount.
