...

/

Track Your Spending (or Habits)

Track Your Spending (or Habits)

Understand how to log structured input to a file.

Let’s build a real-life Python project: a tracker!

Press + to interact

You can use it to log spending, habits, workouts—anything you want to keep a record of.

Step 1: Simple spending logger

while True:
    item = input("Enter an item (or 'done' to finish): ")
    if item == "done":
        break
    amount = input("How much did you spend on it? ")
    with open("expenses.txt", "a") as file:
        file.write(item + ": $" + amount + "\n")  # Concatenate the strings before writing

print("All expenses saved!")
We’re asking the user for what they spent on and how much, and saving it to a file

Note: The item, ": $", amount, and "\n" ...