Courses/Python/Final Projects/Finance Tracker
    ๐Ÿ’ฐ

    Personal Finance Tracker

    Advanced Project

    Track expenses and balance using OOP, JSON, datetime, and error handling.

    Project Overview

    Goal: Track income, expenses, and generate reports.

    Concepts: File I/O, datetime, JSON, formatting, error handling.

    Key Features:

    • โ€ข Add income and expenses
    • โ€ข Categorize transactions
    • โ€ข Generate monthly reports
    • โ€ข Calculate savings rate
    • โ€ข Budget warnings
    • โ€ข Data visualization (optional)

    Technologies & Concepts:

    OOP (Classes)JSONDatetimeFile I/OException Handling

    Starter Code

    ๐Ÿ’ก This full interactive version uses input() which requires a local Python environment.Jump to the Browser Demo below to see a simplified version running in your browser.

    import json
    import datetime
    from pathlib import Path
    
    class FinanceTracker:
        def __init__(self, filename="finance.json"):
            self.filename = filename
            self.data = self.load_data()
        
        def load_data(self):
            """Load existing data or create new structure"""
            try:
                with open(self.filename) as f:
                    return json.load(f)
            except FileNotFoundError:
                return {"transactions": [], "balance": 0}
        
        def save_data(self):
            """Save data to JSON file"""
            with open(self.filename, "w") as f:
                json.dump(self.data, f, indent=2)
        
        def add_transaction(self, amount, description, category="General"):
            """Add income (positive) or expense (negative)"""
            transaction = {
                "amount": amount,
                "description": description,
                "category": category,
                "date": datetime.date.today().isoformat()
            }
            self.data["transactions"].append(transaction)
            self.data["balance"] += amount
            self.save_data()
            
            emoji = "๐Ÿ’ฐ" if amount > 0 else "๐Ÿ’ธ"
            print(f"{emoji} Added: {description} ({amount:,.2f})")
        
        def show_balance(self):
            """Display current balance"""
            balance = self.data["balance"]
            color = "green" if balance >= 0 else "red"
            print(f"๐Ÿ’ต Current Balance: {balance:,.2f}")
        
        def show_transactions(self, limit=10):
            """Show recent transactions"""
            transactions = self.data["transactions"][-limit:]
            print(f"๐Ÿ“œ Recent Transactions (Last {limit}):")
            for t in transactions:
                amount = t["amount"]
                sign = "+" if amount > 0 else ""
                print(f"  {t['date']} | {t['description']:20} | {sign}{amount:,.2f} | {t['category']}")
        
        def monthly_report(self, month=None):
            """Generate report for specific month"""
            if month is None:
                month = datetime.date.today().strftime("%Y-%m")
            
            monthly_txns = [t for t in self.data["transactions"] 
                           if t["date"].startswith(month)]
            
            income = sum(t["amount"] for t in monthly_txns if t["amount"] > 0)
            expenses = sum(t["amount"] for t in monthly_txns if t["amount"] < 0)
            
            print(f"๐Ÿ“Š Report for {month}")
            print(f"   Income: {income:,.2f}")
            print(f"   Expenses: {abs(expenses):,.2f}")
            print(f"   Net: {income + expenses:,.2f}")
    
    # Example usage
    tracker = FinanceTracker()
    tracker.add_transaction(1000, "Salary", "Income")
    tracker.add_transaction(-50, "Groceries", "Food")
    tracker.add_transaction(-30, "Netflix", "Entertainment")
    tracker.add_transaction(200, "Freelance work", "Income")
    tracker.show_balance()
    tracker.show_transactions()
    tracker.monthly_report()

    To run this locally: Save as finance_tracker.py and run python finance_tracker.py

    Browser Demo (Simplified Version)

    This version demonstrates the core functionality without requiring user input. Click "Run" to see it in action!

    Finance Tracker Demo

    Try it Yourself ยป
    Python
    from datetime import datetime
    
    class FinanceTracker:
        def __init__(self):
            self.transactions = []
            self.balance = 0
        
        def add_transaction(self, amount, description, category="General"):
            """Add income (positive) or expense (negative)"""
            transaction = {
                "amount": amount,
                "description": description,
                "category": category,
                "date": datetime.now().strftime("%Y-%m-%d")
            }
            self.transactions.append(trans
    ...

    Enhancement Ideas ๐Ÿš€

    1. Budget System

    Set monthly budgets for categories and get warnings when approaching limits.

    2. Data Visualization

    Use matplotlib to create charts showing spending by category over time.

    3. Recurring Transactions

    Add support for recurring monthly expenses (rent, subscriptions).

    4. Multi-Currency Support

    Track transactions in different currencies with automatic conversion.

    5. Export to CSV/Excel

    Allow exporting transaction history for analysis in spreadsheet software.

    Next Steps

    1. Test the tracker with sample transactions
    2. Add category management (add/edit/delete categories)
    3. Implement search and filter functionality
    4. Create yearly comparison reports
    5. Add data visualization with charts
    6. Build a budget tracking system
    7. Consider adding user authentication for privacy
    Back to Projects

    Cookie & Privacy Settings

    We use cookies to improve your experience, analyze traffic, and show personalized ads. You can manage your preferences below.

    By clicking "Accept All", you consent to our use of cookies for analytics and personalized advertising. You can customize your preferences or reject non-essential cookies.

    Privacy Policy โ€ข Terms of Service