Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here is a straightforward, functional Python script to help you track your spending. It uses a dictionary to store categories and their respective totals, making it easy to see where your money is going.
- # Simple Personal Budget Tracker
- # Categories: groceries, transport, entertainment, dining, etc.
- budget = {
- "groceries": 0.0,
- "transport": 0.0,
- "entertainment": 0.0,
- "dining": 0.0,
- "other": 0.0
- }
- def add_expense():
- print("\nAvailable: groceries, transport, entertainment, dining, other")
- category = input("Enter category: ").lower()
- if category in budget:
- try:
- amount = float(input(f"Amount for {category}: "))
- budget[category] += amount
- print("Successfully added!")
- except ValueError:
- print("Error: Please enter a number.")
- else:
- print("Category not found.")
- def show_balance():
- print("\n--- Current Spending ---")
- for cat, total in budget.items():
- print(f"{cat.capitalize()}: ${total:.2f}")
- print(f"Total: ${sum(budget.values()):.2f}")
- while True:
- choice = input("\n1. Add Expense | 2. Summary | 3. Exit: ")
- if choice == '1':
- add_expense()
- elif choice == '2':
- show_balance()
- elif choice == '3':
- break
- else:
- print("Invalid choice.")
Advertisement
Add Comment
Please, Sign In to add comment