This is a backend implementation of a group expense splitting application, written in Python 3. It utilizes object-oriented programming (OOP) principles to efficiently manage and settle debts among a group of people. The program calculates individual balances and provides the simplest way to settle all debts with the minimum number of transactions.
- OOP Design: The system is built with a
Personclass to represent each member and aSplitwiseclass to handle the core logic of expense calculation and settlement. - Minimal Transactions: It uses a greedy algorithm to minimize the number of payments required to settle all debts. This ensures an efficient and straightforward settlement process.
- Clear Output: The program outputs a clear list of who needs to pay whom and how much, simplifying the process of settling up.
- Robust Calculations: Handles floating-point numbers and rounds balances to two decimal places, ensuring accurate financial calculations.
- Clone the repository:
git clone [your-repo-url]
- Navigate to the project directory:
cd splitwise - Run the Python script:
python splitwise.py
To use the program, you need to provide a list of payments, where each item is a tuple containing a person's name and the amount they paid.
Example:
payments = [
("Alice", 100),
("Bob", 50),
("Charlie", 70),
("David", 20)
]
splitter = Splitwise(payments)
settlements = splitter.settle()
for s in settlements:
print(s)The output will be a list of payments to settle all debts. For the above example, a possible output would be:
David pays Alice: ₹20.00
Charlie pays Bob: ₹10.00
(Note: The exact output depends on the settlement algorithm's path but will always result in a full settlement.)
- Pranav - B.E. in Computer Science with Business Systems student.