Question: Task 1 Define a Python dataclass ( you must use dataclass not class ) named Product to represent product information. Each product should have the
Task Define a Python dataclass you must use dataclass not class named Product to represent product information. Each product should have the following attributes:
id int: A unique identifier for the product.
name str: The name of the product.
category str: The category to which the product belongs.
price float: The price of the product.
stock int: The number of units available in stock.
Task Write a Python script that performs the following actions:
Reads product data from a file named products.txt Each line in the file follows this format:
idname, category,price,stock
Example data:
Apple, Fruit,
Banana, Fruit,
Milk, Dairy,
Populates a dictionary where the key is the product's id and the value is a Product object created from the file data.
Task Implement the following functionalities:
Total stock value per category: Compute and print the total stock value for each category, where the stock value is defined as price multiplied by stock. This function should take a dictionary as parameter and
Most expensive product: Identify and display the product with the highest price.
Category with the highest stock: Determine which category has the most items in stock calculated as the sum of the stock for all products in the category
All functions in Task should take a single parameter a Python dictionary. Each function in this task must required information like presented in sample output.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
