Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Challenge: Freelance Finance Tracker | Automating Freelance Workflow
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for Freelancers

bookChallenge: Freelance Finance Tracker

Managing your freelance finances efficiently is crucial for long-term success. In this challenge, you will build a Python script that acts as a simple finance tracker. This script will let you add income and expense entries (using hardcoded data for demonstration), categorize each transaction, and then generate a clear summary report. The report will show your total income, total expenses, net profit, and list all transactions grouped by category.

To start, you need to represent your transactions in a way that makes them easy to manage and analyze. You can use a list of dictionaries, where each dictionary holds the details of a single transaction. Each transaction will have an amount, a category, a type ("income" or "expense"), and a description.

123456789
# Hardcoded list of transactions transactions = [ {"amount": 1200, "category": "Web Development", "type": "income", "description": "Website for Client A"}, {"amount": 300, "category": "Graphic Design", "type": "income", "description": "Logo for Client B"}, {"amount": 100, "category": "Software", "type": "expense", "description": "Annual domain registration"}, {"amount": 50, "category": "Office Supplies", "type": "expense", "description": "Printer ink"}, {"amount": 200, "category": "Web Development", "type": "income", "description": "Landing page for Client C"}, {"amount": 75, "category": "Marketing", "type": "expense", "description": "Social media ads"}, ]
copy

With your data structured, you can now calculate the totals for income and expenses. Loop through each transaction, adding up the amounts for each type. The net profit is simply your total income minus your total expenses.

12345678
# Calculate totals total_income = sum(t["amount"] for t in transactions if t["type"] == "income") total_expenses = sum(t["amount"] for t in transactions if t["type"] == "expense") net_profit = total_income - total_expenses print("Total Income: $", total_income) print("Total Expenses: $", total_expenses) print("Net Profit: $", net_profit)
copy

To make your report more useful, you should also list all transactions grouped by category. You can use a dictionary to organize transactions by their category, then print each group with its transactions.

12345678910111213
# Group transactions by category from collections import defaultdict category_groups = defaultdict(list) for t in transactions: category_groups[t["category"]].append(t) print("\nTransactions by Category:") for category, items in category_groups.items(): print(f"\n{category}:") for item in items: sign = "+" if item["type"] == "income" else "-" print(f" {sign}${item['amount']} ({item['description']})")
copy

This approach gives you a simple but flexible way to track your freelance finances, categorize your earnings and expenses, and see your bottom line at a glance. You can expand this script with more features as your needs grow, but this foundation will help you stay organized and informed.

Taak

Swipe to start coding

Create a Python script that tracks freelance income and expenses using hardcoded data. Your script should:

  • Store at least six transactions, with both income and expense entries, each having a category and description.
  • Calculate and print total income, total expenses, and net profit.
  • Print all transactions grouped by category, showing amount, type (income/expense), and description.

Oplossing

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 7
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Suggested prompts:

Can you explain how to add new transactions to the list?

How can I customize the categories for my own needs?

What are some ideas for expanding this script with more features?

close

bookChallenge: Freelance Finance Tracker

Veeg om het menu te tonen

Managing your freelance finances efficiently is crucial for long-term success. In this challenge, you will build a Python script that acts as a simple finance tracker. This script will let you add income and expense entries (using hardcoded data for demonstration), categorize each transaction, and then generate a clear summary report. The report will show your total income, total expenses, net profit, and list all transactions grouped by category.

To start, you need to represent your transactions in a way that makes them easy to manage and analyze. You can use a list of dictionaries, where each dictionary holds the details of a single transaction. Each transaction will have an amount, a category, a type ("income" or "expense"), and a description.

123456789
# Hardcoded list of transactions transactions = [ {"amount": 1200, "category": "Web Development", "type": "income", "description": "Website for Client A"}, {"amount": 300, "category": "Graphic Design", "type": "income", "description": "Logo for Client B"}, {"amount": 100, "category": "Software", "type": "expense", "description": "Annual domain registration"}, {"amount": 50, "category": "Office Supplies", "type": "expense", "description": "Printer ink"}, {"amount": 200, "category": "Web Development", "type": "income", "description": "Landing page for Client C"}, {"amount": 75, "category": "Marketing", "type": "expense", "description": "Social media ads"}, ]
copy

With your data structured, you can now calculate the totals for income and expenses. Loop through each transaction, adding up the amounts for each type. The net profit is simply your total income minus your total expenses.

12345678
# Calculate totals total_income = sum(t["amount"] for t in transactions if t["type"] == "income") total_expenses = sum(t["amount"] for t in transactions if t["type"] == "expense") net_profit = total_income - total_expenses print("Total Income: $", total_income) print("Total Expenses: $", total_expenses) print("Net Profit: $", net_profit)
copy

To make your report more useful, you should also list all transactions grouped by category. You can use a dictionary to organize transactions by their category, then print each group with its transactions.

12345678910111213
# Group transactions by category from collections import defaultdict category_groups = defaultdict(list) for t in transactions: category_groups[t["category"]].append(t) print("\nTransactions by Category:") for category, items in category_groups.items(): print(f"\n{category}:") for item in items: sign = "+" if item["type"] == "income" else "-" print(f" {sign}${item['amount']} ({item['description']})")
copy

This approach gives you a simple but flexible way to track your freelance finances, categorize your earnings and expenses, and see your bottom line at a glance. You can expand this script with more features as your needs grow, but this foundation will help you stay organized and informed.

Taak

Swipe to start coding

Create a Python script that tracks freelance income and expenses using hardcoded data. Your script should:

  • Store at least six transactions, with both income and expense entries, each having a category and description.
  • Calculate and print total income, total expenses, and net profit.
  • Print all transactions grouped by category, showing amount, type (income/expense), and description.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 7
single

single

some-alt