Assignment 3
Assignment 3
Instructions:
You are tasked with building a system to handle order and customer data for an online store.
The system needs to use lambda functions, Python's built-in functions (e.g., map(),
filter(), reduce()), and proper exception handling.
You are given a list of dictionaries where each dictionary represents an order with customer
details.
orders = [
{"customer": "Alice", "total": 250.5},
{"customer": "Bob", "total": "invalid_data"},
{"customer": "Charlie", "total": 450},
{"customer": "Daisy", "total": 100.0},
{"customer": "Eve", "total": -30}, # Invalid total
]
• Uses a lambda function with the filter() built-in function to filter out invalid
orders where the total is either non-numeric or less than zero.
• Uses exception handling to handle any type conversion issues.
• Return the filtered valid orders as a list of dictionaries.
After validating the orders, the store is offering a 10% discount on all orders above $300.
• Uses the map() function with a lambda to apply the discount to qualifying orders.
• Returns a new list with the updated totals for each customer.
Part C: Total Sales Calculation
• Calculate the total sales from the list of valid orders (after applying discounts).
• Takes an integer n and iterates over the first n natural numbers, yielding their squares.