diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..6134dc6 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,93 @@ "\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": 18, + "id": "c5b6afd1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 10, 'mug': 20, 'hat': 30, 'book': 40, 'keychain': 50}" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "products=[\"t-shirt\",\"mug\",\"hat\",\"book\",\"keychain\"]\n", + "inventory={}\n", + "for product in products:\n", + " quantity=int(input(f\"enter the quantity for {product}\"))\n", + " inventory[product]=quantity\n", + "\n", + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "985af248", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'mug'}" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders=set()\n", + "\n", + "added_another=\"yes\"\n", + "\n", + "while added_another==\"yes\":\n", + " product_name=input(\"enter the product you want to add\")\n", + " customer_orders.add(product_name)\n", + " added_another=input(\"do you want to contiune to order product? (yes/no)\")\n", + "customer_orders\n", + "\n", + "\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "af1366e5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "products in customers order {'mug', 'book'}\n", + "updated inventory {'t-shirt': 10, 'mug': 17, 'hat': 30, 'book': 37, 'keychain': 50}\n" + ] + } + ], + "source": [ + "\n", + "for product in customer_orders:\n", + " inventory[product] -= 1\n", + "print(\"products in customers order\",customer_orders)\n", + "print(\"updated inventory\",inventory)\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +137,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.11.9" } }, "nbformat": 4,