Python Assessment
Python Assessment
Objective
Given a predefined `item_list`, write a function that, for a given month and year (e.g., `"2024-11"`),
generates a bill by calculating charges for active items and grouping them appropriately.
✅ Function Signature
"""
Generates a bill for the given month based on the item list.
Parameters:
Returns:
"""
🧩 Requirements
- Include only items whose date range intersects with the selected month.
2. Grouping Logic
- `item_code`
- `rate`
3. Amount Calculation
- Calculate the billable amount for each item based on its active days in the selected month.
4. Total Revenue
📦 Output Format
"line_items": [
"rate": 1080.0,
"qty": 25,
"amount": 27000.0,
},
...
],
"total_revenue": 72000.0
🧩 Hints
- Be mindful of inconsistent data types in fields like `rate`, `qty`, and `amount`.
- Pay close attention to how many days in the month an item is active.
item_list = [
{
"idx": 1,
"qty": 10,
"rate": "1000",
"amount": "10000",
"start_date": "2023-11-01",
"stop_date": "2024-10-17",
},
"idx": 2,
"qty": "10",
"rate": "1080",
"amount": "10800",
"start_date": "2024-10-18",
"stop_date": "2025-10-31",
},
"idx": 3,
"qty": 15,
"rate": "1080",
"amount": "16200",
"start_date": "2024-11-01",
"stop_date": "2025-10-31",
},
"idx": 4,
"item_code": "Executive Desk (4*2)",
"qty": 5,
"rate": "1000",
"amount": "5000",
"start_date": "2024-11-01",
"stop_date": "2025-10-31",
},
"idx": 5,
"qty": 5,
"rate": 5000,
"amount": 25000,
"start_date": "2024-11-01",
"stop_date": "2025-10-31",
},
"idx": 6,
"qty": 7,
"rate": "5000",
"amount": 35000,
"start_date": "2024-12-15",
"stop_date": "2025-10-31",
},
"idx": 7,
"qty": 10,
"rate": 4600,
"amount": 46000,
"start_date": "2023-11-01",
"stop_date": "2024-10-17",
},
"idx": 8,
"qty": 10,
"rate": 1000,
"amount": 10000,
"start_date": "2024-11-01",
"stop_date": "2025-10-31",
},
"idx": 9,
"qty": 10,
"rate": 0,
"amount": 0,
"start_date": "2024-11-01",
"stop_date": "2025-10-31",
},
"idx": 10,
"qty": "8",
"rate": "1100",
"amount": "8800",
"start_date": "2024-11-15",
"stop_date": "2025-01-31",
},
{
"idx": 11,
"qty": "3",
"rate": "5200",
"amount": "15600",
"start_date": "2024-10-10",
"stop_date": "2024-11-10",
},
"idx": 12,
"qty": 1,
"rate": "20000",
"amount": "20000",
"start_date": "2024-11-05",
"stop_date": "2024-11-20",
},
"idx": 13,
"qty": 5,
"rate": "1000",
"amount": "5000",
"start_date": "2024-11-15",
"stop_date": "2025-02-28",
},
"idx": 14,
"qty": 2,
"rate": "7000",
"amount": "14000",
"start_date": "2024-11-01",
"stop_date": "2025-03-31",
},
"idx": 15,
"qty": 1,
"rate": "7000",
"amount": "7000",
"start_date": "2024-11-10",
"stop_date": "2024-11-25",
},
"idx": 16,
"qty": 3,
"rate": "3000",
"amount": "9000",
"start_date": "2024-01-01",
"stop_date": "2024-01-31",