diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..a13488e 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,6 +43,79 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5c7a17d0", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "\n", + "#1\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " quantity = int(input(f\"Enter quantity product {product}: \"))\n", + " inventory[product] = quantity\n", + " return inventory \n", + "\n", + "#2\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + " print(\"Enter the product you want to order.\")\n", + " print (\"Type OK when it's ok.\")\n", + " while True:\n", + " order = input(\"Product name: \")\n", + " if order.lower() == \"OK\":\n", + " break\n", + " customer_orders.add(order)\n", + " return customer_orders\n", + "\n", + "#3\n", + "def update_inventory(customer_orders, inventory):\n", + " for order in customer_orders:\n", + " if order in inventory and inventory[order] > 0:\n", + " inventory [order] -= 1\n", + "\n", + "#4\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_products_ordered = len(customer_orders)\n", + " percent_unique_product = (total_products_ordered / len(products)) * 100 if products else 0\n", + " return total_products_ordered, percent_unique_product\n", + "\n", + "#5\n", + "def print_order_statistics (order_statistics):\n", + " total_products_ordered, percent_unique_product = order_statistics\n", + " print (f\"Order Statistics:\")\n", + " print (f\"Total of the products ordered : {total_products_ordered}\")\n", + " print (f\"Percentage of unique products ordered: {percent_unique_product:.2f}%\")\n", + "\n", + "#6\n", + "def print_updated_inventory(inventory):\n", + " print(\"Updated Inventory\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product: {quantity}}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c03ac5e7", + "metadata": {}, + "outputs": [], + "source": [ + "def exe():\n", + " inventory = initialize_inventory(products)\n", + " customer_orders = get_customer_orders()\n", + " update_inventory(customer_orders, inventory)\n", + " order_statistics = calculate_order_statistics(customer_orders, products)\n", + " print_order_statistics(order_statistics)\n", + " print_updated_inventory(inventory)" + ] } ], "metadata": {