diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f0064cb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "python.testing.unittestArgs": [ + "-v", + "-s", + ".", + "-p", + "*test*.py" + ], + "python.testing.pytestEnabled": false, + "python.testing.unittestEnabled": true +} \ No newline at end of file diff --git a/__pycache__/analytics.cpython-313.pyc b/__pycache__/analytics.cpython-313.pyc new file mode 100644 index 0000000..3226b1d Binary files /dev/null and b/__pycache__/analytics.cpython-313.pyc differ diff --git a/__pycache__/test_analytics.cpython-313.pyc b/__pycache__/test_analytics.cpython-313.pyc new file mode 100644 index 0000000..0c26a39 Binary files /dev/null and b/__pycache__/test_analytics.cpython-313.pyc differ diff --git a/analytics.py b/analytics.py index 8acadc8..179a525 100644 --- a/analytics.py +++ b/analytics.py @@ -1,3 +1,4 @@ +import statistics # ========================================== # SECTION A: LIST PROCESSING # ========================================== @@ -17,9 +18,12 @@ def filter_sales_above_threshold(sales: list, threshold: int): - Use a loop or list comprehension """ # TODO: Write your code here - pass - - + new_list = [] + for i in sales: + if i >= threshold: + new_list.append(i) + return new_list +# print(filter_sales_above_threshold([100, 250, 75, 300], 150)) def count_product_codes(codes: list, prefix: str): """ QUESTION 2 @@ -33,7 +37,13 @@ def count_product_codes(codes: list, prefix: str): - Return 0 if no matches found """ # TODO: Write your code here - pass + count = 0 + for code in codes: + code = str(code) + if code.startswith(prefix): + count += 1 + return count +# print(count_product_codes(["PROD-001", "PROD-002", "SERV-001"], "PROD")) def calculate_moving_average(numbers: list, window_size: int): @@ -51,7 +61,13 @@ def calculate_moving_average(numbers: list, window_size: int): - Return 0.0 for empty list """ # TODO: Write your code here - pass + if numbers == []: + return float(0) + + new = numbers[-window_size:] + + return float(statistics.mean(new)) +# print(calculate_moving_average([], 3)) # ========================================== @@ -72,8 +88,25 @@ def get_top_seller(sales_data: dict): - If there's a tie, return the name that appears first alphabetically """ # TODO: Write your code here - pass + if sales_data == {}: + return "No Data" + sales = [] + length = len(sales_data.keys()) + sales =(sorted(sales_data.values())) + print(sales) + names = sorted(sales_data.keys()) + if len(names) == 1: + return names[0] + if sales[0] == sales[1]: + return names[0] + for name, sale in sales_data.items(): + if sale == sales[-1]: + return name + return name + + +print(get_top_seller({"Alice": 5000, "Bob": 7500, "Carol": 6000})) def merge_inventory(warehouse_a: dict, warehouse_b: dict): """ @@ -93,7 +126,15 @@ def merge_inventory(warehouse_a: dict, warehouse_b: dict): - Do NOT modify the original dictionaries """ # TODO: Write your code here - pass + new = {} + for key, value in warehouse_a.items(): + for key1, value1 in warehouse_b.items(): + if key == key1: + nv = value+ value1 + return new[k] +warehouse_a = {"PROD-001": 50, "PROD-002": 30} +warehouse_b = {"PROD-002": 20, "PROD-003": 40} +print(merge_inventory(warehouse_a,warehouse_b)) # ==========================================