diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..0b43f06 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,63 @@ "\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": "0b9dd6bc", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {} \n", + "\n", + "for item in products:\n", + " quantity = int(input(\"Enter the number of product available: \"))\n", + " inventory[item] = quantity\n", + "\n", + "customer_orders = set()\n", + "\n", + "while True:\n", + " product = input(\"Enter the product name: \").lower()\n", + " \n", + " if product in products:\n", + " customer_orders.add(product) \n", + " else:\n", + " print(\"Invalid product. Please choose from:\", products)\n", + " while True:\n", + " add_more = input(\"Do you want to order another product? (yes/no): \").lower()\n", + " if add_more in (\"yes\", \"no\"):\n", + " break\n", + " print(\"Please answer in 'yes' or 'no'.\")\n", + " if add_more == \"no\":\n", + " break\n", + " \n", + "print(\"Products in customer orders:\", customer_orders)\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "print(\"Order Statistics\")\n", + "print(\"Total Products Ordered:\", order_status[0])\n", + "print(\"Percentage of Products Ordered:\", order_status[1], \"%\")\n", + "\n", + "for product_name in customer_orders:\n", + " if product_name in inventory:\n", + " inventory[product_name] -= 1\n", + "\n", + "print(\"Updated Inventory:\")\n", + "for item in products:\n", + " print(f\"{item}, Quantity Left: {inventory[item]}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +107,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.2" } }, "nbformat": 4,