Challenge: Build a Sales Report Generator

Get an overview of a sales report-generating system and implement it using functional programming intersection.

We'll cover the following

Problem statement

A corporation needs a program to generate monthly sales reports for its international operations. The sales data is provided in the CSV file format and includes information on products, categories, quantities, and prices. The program should calculate total sales, identify top-selling products, calculate average sales per category, and generate formatted sales reports for each country.

Tasks

  • Implement a function to read sales data from a CSV file and return it as a list of dictionaries.

  • Write a function to calculate the total sales for each country and return a dictionary with country names as keys and total sales as values.

  • Implement a function to identify the top-selling products across all countries and return a list of tuples containing product names and total quantities sold.

  • Write a function to calculate the average sales per product category for each country and return a dictionary with country names as keys and inner dictionaries with category names and average sales as values.

  • Implement a function to generate a sales report for each country. The report should include total sales, top-selling products, and average sales per category. Write the report in a text file.

  • Use the @contextmanager decorator to create a context manager for file I/O operations in the sales report generator. The context manager should handle the opening and closing of the report file automatically.

Note: You may practice writing your code in the playground below before moving to its solution lesson.

Get hands-on with 1400+ tech skills courses.