Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Expense Splitter

Description

A practical Python application that helps split expenses fairly among multiple people. Supports equal splits, splits with tips, and custom splits with different ratios. Perfect for splitting restaurant bills, shared expenses, or group activities.

Features

  • Equal Split: Divide expenses equally among all people
  • Split with Tip: Calculate split including tip percentage
  • Custom Split: Different ratios for different people
  • Multiple currency support
  • Type hints for better code quality
  • Formatted output with thousands separators
  • Input validation and error handling
  • Interactive menu system
  • Recursive option to calculate multiple splits

Stack

  • Language: Pure Python
  • Libraries: None (pure Python standard library)
  • Complexity: Beginner

Installation

No external dependencies required!

# Run the program
python main.py

Usage

Equal Split

python main.py

Select option 1 and follow prompts:

Enter total expense amount: 1500
Enter number of people: 3
Enter currency symbol (default $): ₹

==================================================
           EXPENSE SPLIT CALCULATION
==================================================
Total expenses:        ₹1,500.00
Number of people:      3
Each person should pay: ₹500.00
==================================================

Split with Tip

Select option 2:

Enter total expense amount (before tip): 100
Enter number of people: 4
Enter tip percentage (e.g., 15 for 15%): 15
Enter currency symbol (default $): $

==================================================
           EXPENSE SPLIT WITH TIP
==================================================
Subtotal:              $100.00
Tip (15.0%):           $15.00
Total with tip:        $115.00
Number of people:      4
Each person should pay: $28.75
==================================================

Custom Split

Select option 3 for different ratios:

Enter total expense amount: 300
Enter currency symbol (default $): $

Enter person names and their share ratios
(e.g., if Alice pays 2x and Bob pays 1x, enter 2 for Alice and 1 for Bob)
Enter blank name to finish

Person name: Alice
  Share ratio for Alice: 2
Person name: Bob
  Share ratio for Bob: 1
Person name: Charlie
  Share ratio for Charlie: 1
Person name: 

==================================================
           CUSTOM EXPENSE SPLIT
==================================================
Total expenses: $300.00

Individual shares:
------------------------------------------------------------
Alice                ( 50.0%): $150.00
Bob                  ( 25.0%): $75.00
Charlie              ( 25.0%): $75.00
==================================================

How It Works

Equal Split Algorithm

share_per_person = total_amount / number_of_people

Split with Tip Algorithm

tip_amount = total_amount * (tip_percentage / 100)
total_with_tip = total_amount + tip_amount
share_per_person = total_with_tip / number_of_people

Custom Split Algorithm

total_shares = sum(all_share_ratios)
person_amount = (person_share / total_shares) * total_amount

Functions

calculate_split(total_amount, number_of_people, currency)

Calculates equal split among all people.

Parameters:

  • total_amount (float): Total expense
  • number_of_people (int): Number of people
  • currency (str): Currency symbol

calculate_with_tip(total_amount, number_of_people, tip_percentage, currency)

Calculates split including tip.

Parameters:

  • total_amount (float): Subtotal before tip
  • number_of_people (int): Number of people
  • tip_percentage (float): Tip percentage
  • currency (str): Currency symbol

calculate_custom_split(total_amount, shares, currency)

Calculates split with custom ratios.

Parameters:

  • total_amount (float): Total expense
  • shares (dict): Dictionary of {name: ratio}
  • currency (str): Currency symbol

Use Cases

Restaurant Bill

  • Split bill equally among friends
  • Include tip calculation
  • Handle different payment ratios (someone orders more)

Shared Apartment

  • Split rent and utilities
  • Different room sizes = different ratios
  • Monthly recurring expenses

Group Trip

  • Split hotel costs
  • Divide transportation expenses
  • Share activity costs

Office Lunch

  • Split delivery order
  • Include delivery fee and tip
  • Handle different meal costs

Example Scenarios

Scenario 1: Restaurant Dinner

4 friends, $120 bill, 18% tip
Result: Each pays $35.40

Scenario 2: Apartment Rent

3 roommates, $1500 rent
Alice (master bedroom): 2 shares
Bob (regular room): 1 share
Charlie (regular room): 1 share
Result: Alice $750, Bob $375, Charlie $375

Scenario 3: Group Gift

5 people, $100 gift
Result: Each contributes $20.00

Error Handling

  • Validates number of people ≥ 1
  • Checks for valid numeric input
  • Handles division by zero
  • Validates share ratios
  • Catches keyboard interrupts
  • Provides clear error messages

Customization

Add Tax Calculation

def calculate_with_tax_and_tip(total, people, tax_pct, tip_pct, currency="$"):
    tax = total * (tax_pct / 100)
    subtotal_with_tax = total + tax
    tip = subtotal_with_tax * (tip_pct / 100)
    grand_total = subtotal_with_tax + tip
    per_person = grand_total / people
    return per_person

Add Payment Tracking

def track_payments(shares, paid):
    """Track who has paid and who owes"""
    for person, amount in shares.items():
        status = "✓ Paid" if person in paid else "✗ Pending"
        print(f"{person}: ${amount:.2f} - {status}")

Export to CSV

import csv

def export_split(filename, data):
    with open(filename, 'w', newline='') as f:
        writer = csv.writer(f)
        writer.writerow(['Person', 'Amount', 'Currency'])
        for person, amount in data.items():
            writer.writerow([person, amount, currency])

Learning Outcomes

  • Function design with type hints
  • Dictionary operations
  • String formatting with f-strings
  • Input validation
  • Error handling with try-except
  • Mathematical calculations
  • User interface design (CLI)
  • Code organization and modularity

Future Enhancements

  • GUI version with Tkinter
  • Save split history to database
  • Generate payment links (Venmo, PayPal)
  • QR code generation for payments
  • Email/SMS notifications
  • Multiple currency conversion
  • Receipt scanning (OCR)
  • Group expense tracking over time
  • Settle up calculations (who owes whom)
  • Export to PDF/Excel
  • Mobile app version
  • Integration with payment apps

Common Tip Percentages

Service Quality Tip %
Poor 10%
Average 15%
Good 18%
Excellent 20%
Outstanding 25%+

Currency Symbols

  • $ - US Dollar, Canadian Dollar, Australian Dollar
  • - Euro
  • £ - British Pound
  • ¥ - Japanese Yen, Chinese Yuan
  • - Indian Rupee
  • - Russian Ruble
  • - South Korean Won

License

This project is open source and available for educational purposes.