Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele 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.

Tehtävä

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.

Ratkaisu

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 7
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

close

bookChallenge: Freelance Finance Tracker

Pyyhkäise näyttääksesi valikon

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.

Tehtävä

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.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 7
single

single

some-alt