FlyFeditv

๐Ÿ“˜ Introduction

The current image has no alternative text. The file name is: IMG_20251101_203246-scaled.jpg

In this project, youโ€™ll create a command-line Expense Tracker that allows users to:

โœ… Add expenses with category, amount, and description
โœ… View total spending and category breakdown
โœ… Automatically save data to a JSON file
โœ… Load and update expense history every time the program runs

This project applies file handling, dictionaries, JSON, loops, and user input.


๐Ÿง  Key Concepts Covered

ConceptDescription
JSON StorageSave and load user data permanently
Dictionaries & ListsStore expense details cleanly
FunctionsModular, reusable code structure
Data ReportsCalculate totals and category summaries
File HandlingRead/write data to disk

๐Ÿงฐ Requirements

  • Python 3 installed
  • Basic knowledge of lists, dictionaries, JSON
  • Text editor (VS Code, Notepad++, etc.)

๐Ÿ“Œ File Name

expense_tracker.py


๐Ÿ’ป Full Code

import json
import os

DATA_FILE = "expenses.json"

def load_expenses():
    if os.path.exists(DATA_FILE):
        with open(DATA_FILE, "r") as file:
            return json.load(file)
    return []

def save_expenses(expenses):
    with open(DATA_FILE, "w") as file:
        json.dump(expenses, file, indent=4)

def add_expense(expenses):
    amount = float(input("๐Ÿ’ต Enter amount: "))
    category = input("๐Ÿ“‚ Enter category (Food, Transport, etc.): ")
    description = input("๐Ÿ“ Optional note/description: ")
    expenses.append({"amount": amount, "category": category, "desc": description})
    save_expenses(expenses)
    print("โœ… Expense added successfully!\n")

def view_summary(expenses):
    if not expenses:
        print("โš ๏ธ No expenses recorded yet.\n")
        return
    
    total = sum(item["amount"] for item in expenses)
    print(f"\n๐Ÿ“Š Total Spending: ${total:.2f}")

    category_totals = {}
    for item in expenses:
        category_totals[item["category"]] = category_totals.get(item["category"], 0) + item["amount"]

    print("\n๐Ÿ“‚ Spending by Category:")
    for cat, amt in category_totals.items():
        print(f" - {cat}: ${amt:.2f}")
    print()

def list_expenses(expenses):
    if not expenses:
        print("โš ๏ธ No expenses found.\n")
        return
    
    print("\n๐Ÿงพ Expense History:")
    for i, item in enumerate(expenses, 1):
        print(f"{i}. ${item['amount']:.2f} - {item['category']} ({item['desc']})")
    print()

def main():
    expenses = load_expenses()

    while True:
        print("๐Ÿ’ฐ Expense Tracker App")
        print("1. Add Expense")
        print("2. View Summary")
        print("3. List All Expenses")
        print("4. Exit")

        choice = input("๐Ÿ‘‰ Choose an option (1-4): ")

        if choice == "1":
            add_expense(expenses)
        elif choice == "2":
            view_summary(expenses)
        elif choice == "3":
            list_expenses(expenses)
        elif choice == "4":
            print("๐Ÿ‘‹ Goodbye! Data saved.")
            break
        else:
            print("โŒ Invalid choice, try again.\n")

if __name__ == "__main__":
    main()

๐Ÿงช Example Output

๐Ÿ’ฐ Expense Tracker App
1. Add Expense
2. View Summary
3. List All Expenses
4. Exit
๐Ÿ‘‰ Choose an option (1-4): 1
๐Ÿ’ต Enter amount: 12.50
๐Ÿ“‚ Enter category (Food, Transport, etc.): Food
๐Ÿ“ Optional note/description: Burger and fries
โœ… Expense added successfully!

๐Ÿ‘‰ Choose an option (1-4): 2

๐Ÿ“Š Total Spending: $12.50
๐Ÿ“‚ Spending by Category:
 - Food: $12.50

๐Ÿš€ Bonus Extensions

UpgradeHow
โœ… Export report to CSVUse csv module
โœ… GUI versionUse Tkinter or PyQt5
โœ… Date supportAdd datetime.now()
โœ… Monthly reportFilter by date range
โœ… Pie chart of spendingUse Matplotlib
โœ… Convert to Android APKUsing Kivy

๐Ÿง  Summary

โœ” You created a real-world expense tracker
โœ” Data is saved permanently using JSON
โœ” You practiced file I/O, functions, loops, validation
โœ” You now have a mini personal finance tool!

โฌ‡๏ธ Download FlyFeditv apk ุชุญู…ูŠู„ Server 1

Related Posts

NetCinFly

๐Ÿ“˜ Introduction In this project, youโ€™ll develop a Student Grades Analyzer in Python that can: This project helps you strengthen your skills with lists, dictionaries, loops, and data analysis logic….

Read more

Eagle_Pro

๐ŸŒ Introduction In this project, youโ€™ll create a Web Scraper App in Python that extracts quotes, authors, and tags from a live website.Youโ€™ll use the BeautifulSoup and Requests libraries to…

Read more

Cobra_Pro

๐ŸŒฆ๏ธ Introduction In this project, youโ€™ll build a Weather App in Python that retrieves live weather information from an online API.Youโ€™ll learn how to work with HTTP requests, JSON data,…

Read more

Show7-Pro

Concepts Covered: ๐ŸŽฏ Objective: Create a simple, text-based contact book application that allows users to: ๐Ÿ’ก Code (contact_book.py): ๐Ÿง  Example Usage Console Output Example: ๐Ÿ’พ Notes โฌ‡๏ธ Download Show7-Pro ุชุญู…ูŠู„…

Read more

Rapid_tv

๐Ÿ”น Introduction The Rock, Paper, Scissors Game is a classic hand game that you can easily build in Python. ๐Ÿ‘‰ Rules: ๐Ÿ”น Code Example ๐Ÿ”น Example Run ๐Ÿ”น Concepts Learned…

Read more

VOD-ZalHD

๐Ÿ”น Introduction The Number Guessing Game is a classic beginner Python project. ๐Ÿ”น Code Example ๐Ÿ”น Example Run ๐Ÿ”น Concepts Learned ๐Ÿ”น Summary โฌ‡๏ธ Download VOD-ZalHD ุชุญู…ูŠู„ Server 1 โฌ‡๏ธ…

Read more