diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..7262840 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,6 +37,72 @@ "\n", "3. Instead of updating the inventory by subtracting 1 from the quantity of each product, only do it for the products that were ordered (those in \"customer_orders\")." ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5e832c33", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "# 1.\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# 2.\n", + "inventory = {}\n", + "\n", + "# 3.\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product} available in inventory: \"))\n", + " inventory[product] = quantity\n", + "\n", + "# 4.\n", + "customer_orders = set()\n", + "\n", + "# 5.\n", + "while True:\n", + " order = input(\"Enter the name of a product to order (t-shirt, mug, hat, book, keychain): \").strip().lower()\n", + " \n", + " if order in products:\n", + " customer_orders.add(order)\n", + " print(f\"{order} added to your order.\")\n", + " else:\n", + " print(f\"Invalid product. Please choose from: {', '.join(products)}\")\n", + " continue\n", + " \n", + " another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " if another != \"yes\":\n", + " break\n", + "\n", + "# 6.\n", + "print(\"Customer Orders:\", customer_orders)\n", + "\n", + "# 7.\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "# 8.\n", + "print(f\"\"\"\n", + "Order Statistics:\n", + "Total Products Ordered: {order_status[0]}\n", + "Percentage of Products Ordered: {order_status[1]:.2f}%\n", + "\"\"\")\n", + "\n", + "# 9.\n", + "for product in customer_orders:\n", + " inventory[product] -= 1\n", + "\n", + "# 10.\n", + "print(\"Updated Inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] } ], "metadata": {