diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..fa40f32 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,13 +37,132 @@ "\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": 23, + "id": "d661c4e0-52b1-4756-927e-4ce789910440", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity of t-shirt: 56\n", + "Enter the quantity of mug: 7\n", + "Enter the quantity of hat: 3\n", + "Enter the quantity of book: 56\n", + "Enter the quantity of keychain: 8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 56, 'mug': 7, 'hat': 3, 'book': 56, 'keychain': 8}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product]=quantity\n", + "\n", + "print (inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "0dfd1b17-122f-484c-a7d9-9f72d68c167f", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the name of a product: book\n", + "Do you want to add another product? yes\n", + "Enter the name of a product: keychain\n", + "Do you want to add another product? yes\n", + "Enter the name of a product: t-shirt\n", + "Do you want to add another product? no\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The customers order is: {'book', 't-shirt', 'keychain'}\n" + ] + } + ], + "source": [ + "customer_orders = set()\n", + "condition=1\n", + "while condition == 1:\n", + " product = input(f\"Enter the name of a product: \").lower()\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"The product isn't in the list.\")\n", + " \n", + " cond = input(\"Do you want to add another product? \").lower()\n", + " \n", + " if cond == \"yes\":\n", + " condition=1\n", + " elif cond == \"no\":\n", + " condition=0\n", + " else:\n", + " print(\"Wrong answer.\")\n", + " condition=0\n", + "print(\"The customers order is:\", customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "4a20dbf6-9832-4581-8a19-d7a6da0605ad", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated inventory: \n", + "t-shirt: 55\n", + "mug: 7\n", + "hat: 3\n", + "book: 55\n", + "keychain: 7\n" + ] + } + ], + "source": [ + "for product in customer_orders:\n", + " inventory[product] -= 1\n", + " \n", + "print(\"Updated inventory: \")\n", + "for product in inventory:\n", + " print(f\"{product}: {inventory[product]}\") " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "726e83ff-1dab-4e41-bbf9-bd439820d573", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -55,7 +174,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,