diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..1eb90e20 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,81 @@ "\n", "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity of t-shirt: 1\n", + "Enter the quantity of mug: 2\n", + "Enter the quantity of hat: 3\n", + "Enter the quantity of book: 4\n", + "Enter the quantity of keychain: 5\n", + "Enter one of these products : ['t-shirt', 'mug', 'hat', 'book', 'keychain'] mug\n", + "Enter one of these products : ['t-shirt', 'mug', 'hat', 'book', 'keychain'] hat\n", + "Enter one of these products : ['t-shirt', 'mug', 'hat', 'book', 'keychain'] book\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is the customer order : {'mug', 'hat', 'book'}\n", + "Order Statistics:\n", + "Total Products Ordered: 3.\n", + "Percentage of Products Ordered: 20.00%. \n", + "This is the inventory after customer order :\n", + "t-shirt : 1\n", + "mug : 1\n", + "hat : 2\n", + "book : 3\n", + "keychain : 5\n" + ] + } + ], + "source": [ + "list_products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "customer_orders = set()\n", + "\n", + "for product in list_products :\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product] = quantity\n", + " \n", + "for order in range (3):\n", + " customer_orders.add(input(f\"Enter one of these products : {list_products}\"))\n", + " \n", + "total_prod_ordered = len(customer_orders)\n", + "total_inventory = sum(inventory.values()) \n", + "percentage_products_ordered = (total_prod_ordered / total_inventory)*100\n", + "order_status = (total_prod_ordered, percentage_products_ordered) \n", + "\n", + "for product in customer_orders :\n", + " if product in inventory and inventory[product] > 0:\n", + " inventory[product] -= 1\n", + " \n", + "\n", + "print(f\"This is the customer order : {customer_orders}\")\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}.\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%. \")\n", + "\n", + "print(f\"This is the inventory after customer order :\")\n", + "for product, quantity in inventory.items():\n", + " print (f\"{product} : {quantity}\") \n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -68,7 +143,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,