"Python Expense Tracker"

 Here is a simple implementation of an expense tracker program in Python:

Explanation:

  • The expenses dictionary will store the date-expense pairs, where the expense is represented as a tuple of amount and category.
  • The add_expense function takes in a date, amount, and category, and adds the key-value pair to the expenses dictionary.
  • The get_expense function takes in a date and returns the corresponding expense from the expenses dictionary. If the date is not found in the dictionary, it returns a default message "Expense not found."
  • The get_total_expense function calculates and returns the total expenses by summing up the amounts.
  • The code adds two expenses to the expenses dictionary and retrieves the expenses for both dates. It also calculates and returns the total expenses.

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.