Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Freelance Finance Tracker | Automating Freelance Workflow
Practice
Projects
Quizzes & Challenges
Вікторини
Challenges
/
Python for Freelancers
Секція 1. Розділ 7
single

single

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.

Завдання

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.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 7
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

some-alt