diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..9629d4e 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,101 @@ "\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": "7ab9c701", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = []\n", + "print(\"select quantity of available product: \")\n", + "for product in products:\n", + " quantity = int(input(f\"{product}: \"))\n", + " inventory[product] = quantity\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "433810a5", + "metadata": {}, + "outputs": [], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c8331fd0", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()\n", + "print(\"Select product to order: \")\n", + "for product in products:\n", + " order = input(f\"Do you want to order {product}? (yes/no): \")\n", + " if order.lower() == \"yes\":\n", + " customer_orders.add(product)\n", + " print(\"Order added.\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "de908393", + "metadata": {}, + "outputs": [], + "source": [ + "print(\"Would you like to add another product)\")\n", + "while True:\n", + " another_order = input(\"Add another product? (yes/no): \")\n", + " if another_order.lower() == \"yes\":\n", + " product = input(\"Enter the product name: \")\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " print(\"Order added.\")\n", + " else:\n", + " print(\"Product not available.\")\n", + " elif another_order.lower() == \"no\":\n", + " break\n", + " else:\n", + " print(\"Invalid input. Please enter 'yes' or 'no'.\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3289e148", + "metadata": {}, + "outputs": [], + "source": [ + "print(\"\\ncustomer_orders:\")\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f884d232", + "metadata": {}, + "outputs": [], + "source": [ + "for product in set(customer_orders):\n", + " if product in inventory and inventory[product] > 0:\n", + " inventory[product] -= 1\n", + " print(\"\\nUpdated Inventory:\")\n", + " for item, quantity in inventory.items():\n", + " print(f\"{item}: {quantity}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +145,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,