Congratulations! You’ve reached the end of the course. It’s time to take everything you’ve learned—Variables, Loops, Logic, Functions, and Lists—and build one real-world application.
The Project: The Personal Expense Tracker
We are going to build a tool that helps a user track their spending and tells them if they are staying within their budget.
🚀 The Requirements:
- The Goal: Ask the user for their total monthly budget.
- The Loop: Allow the user to keep adding expenses (description and cost).
- The Logic: After each expense, tell them how much money they have left.
- The Exit: If they run out of money, warn them! If they type “done”, show them a summary and exit.
💻 The Final Code (The Solution):
Copy this into your editor to see how a full program looks!
Python
def show_summary(expenses, budget):
total_spent = sum(expenses)
remaining = budget - total_spent
print("\n--- FINAL SUMMARY ---")
print("Total Budget: $" + str(budget))
print("Total Spent: $" + str(total_spent))
print("Remaining: $" + str(remaining))
def main():
print("Welcome to the Python Expense Tracker!")
# 1. Get the initial budget
budget = float(input("What is your total budget for this month? "))
expenses = []
running = True
while running:
print("\n--- Current Balance: $" + str(budget - sum(expenses)) + " ---")
item = input("Enter expense name (or 'done' to finish): ")
if item.lower() == 'done':
running = False
else:
cost = float(input("How much did '" + item + "' cost? "))
expenses.append(cost)
# Check if over budget
if sum(expenses) > budget:
print("⚠️ WARNING: You have exceeded your budget!")
# 2. Show final results
show_summary(expenses, budget)
# Start the program
main()
🎖️ Graduation
You have officially moved from “I want to learn” to “I can build.” You now have a solid foundation in the world’s most popular programming language.
- Encourage your readers to change the code (e.g., “Add a feature that categories expenses like ‘Food’ or ‘Rent’”).
- Link to Python.org for further documentation.
