Budget Tracking App :
Project Description:
The Budget App is a simple Python application designed to help users manage their finances
by tracking expenses against an initial budget. It offers functionalities to add expenses,
display budget details, and exit the application. The app stores budget data in a JSON file,
ensuring persistence across sessions..
Statement of Problem:
In today's fast-paced world, managing personal finances efficiently is crucial for financial stability.
However, many individuals struggle to keep track of their expenses and adhere to a budget.
Traditional methods of budgeting, such as manual tracking on paper or spreadsheets, can be
cumbersome and prone to errors.
To address these challenges, the Budget App aims to provide a user-friendly solution for
managing expenses and budgets. By offering a simple interface to add expenses and view
budget details, the app empowers users to make informed financial decisions and stay within
their budgetary constraints. Additionally, by storing budget data in a structured format like JSON,
the app ensures data persistence and accessibility across different sessions, enhancing user
experience and convenience.
Source code:
import json
def add_expense(expenses, description, amount):
expenses.append({"description": description, "amount": amount})
print(f"Added expense: {description}, Amount: {amount}")
def get_total_expenses(expenses):
return sum(expense['amount'] for expense in expenses)
def get_balance(budget, expenses):
return budget - get_total_expenses(expenses)
def show_budget_details(budget, expenses):
print(f"Total Budget: {budget}")
print("Expenses:")
for expense in expenses:
print(f"- {expense['description']}: {expense['amount']}")
print(f"Total Spent: {get_total_expenses(expenses)}")
print(f"Remaining Budget: {get_balance(budget, expenses)}")
def load_budget_data(filepath):
try:
with open(filepath, 'r') as file:
data = json.load(file)
return data['initial_budget'], data['expenses']
except (FileNotFoundError, json.JSONDecodeError):
return 0, [] # Return default values if the file doesn't exist or is empty/corrupted
def save_budget_data(filepath, initial_budget, expenses):
data = {
'initial_budget': initial_budget,
'expenses': expenses
with open(filepath, 'w') as file:
json.dump(data, file, indent=4)
def main():
print("Welcome to the Budget App")
initial_budget = float(input("Please enter your initial budget: "))
# filepath = 'budget_data.json' # Define the path to your JSON file
# initial_budget, expenses = load_budget_data(filepath)
budget = initial_budget
expenses = []
while True:
print("\nWhat would you like to do?")
print("1. Add an expense")
print("2. Show budget details")
print("3. Exit")
choice = input("Enter your choice (1/2/3): ")
if choice == "1":
description = input("Enter expense description: ")
amount = float(input("Enter expense amount: "))
add_expense(expenses, description, amount)
elif choice == "2":
show_budget_details(budget, expenses)
elif choice == "3":
print("Exiting Budget App. Goodbye!")
break
else:
print("Invalid choice, please choose again.")
if __name__ == "__main__":
main()