pythonbeginner10 minutes

Simple Budget Tracker Mini Project

Create a basic budget tracker that lets users add income, add expenses, and get their current balance. This beginner-friendly mini project practices using functions, variables, conditionals, and loops.

Challenge prompt

Build a Python function called `budget_tracker` that repeatedly allows a user to add an income or expense entry. The function should take no arguments and run a simple interactive loop, prompting the user to input 'income' or 'expense', then ask for the amount (a positive number). Keep a running total of income and expenses separately. When the user types 'quit', the function should print the total income, total expenses, and the current balance (income minus expenses) and then exit.

Guidance

  • Use a while loop to keep asking the user for input until they type 'quit'.
  • Use variables to store the total income and total expenses.
  • Make sure to convert input amounts to floats for calculation.
  • Add simple input validation to ensure amount entered is a positive number.

Hints

  • You can use the input() function to get user input and float() to convert strings to numbers.
  • Use if-elif-else statements to handle the different user commands ('income', 'expense', 'quit').
  • Keep your code organized by updating the totals inside the loop based on the user’s action.

Starter code

def budget_tracker():
    income_total = 0.0
    expense_total = 0.0
    while True:
        action = input("Enter 'income', 'expense', or 'quit': ")
        # Your code here

Expected output

Enter 'income', 'expense', or 'quit': income Enter amount: 1000 Enter 'income', 'expense', or 'quit': expense Enter amount: 300 Enter 'income', 'expense', or 'quit': quit Total Income: 1000.0 Total Expenses: 300.0 Current Balance: 700.0

Core concepts

loopsconditionalsinput/outputvariables

Challenge a Friend

Send this duel to someone else and see if they can solve it.