diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..b36fb69 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,91 @@ "\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": 1, + "id": "5875eb86", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug': 2, 'hat': 3, 'keychain': 5, 'book': 1, 't-shirt': 2}\n" + ] + } + ], + "source": [ + "inventory = {'mug':0, 'hat':0, 'keychain':0, 'book':0, 't-shirt':0}\n", + "\n", + "for item in inventory:\n", + " product = input (\"Enter a value\")\n", + " if product in inventory:\n", + " value = (int(input(\"Enter a value\")))\n", + " inventory[item]=value\n", + "\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "3b41c672", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Availability: {'mug': 2, 'hat': 3, 'keychain': 5, 'book': 1, 't-shirt': 2}\n", + "{'t-shirt'}\n", + "Thanks for your purchase.\n" + ] + } + ], + "source": [ + "customer_orders = set()\n", + "\n", + "continue_buying = \"Yes\"\n", + "\n", + "while continue_buying == \"Yes\":\n", + " print(\"Availability:\", inventory)\n", + " product = input(\"What do you want to buy?: \")\n", + " customer_orders.add(product)\n", + " print(customer_orders)\n", + " continue_buying = input(\"Do you want to continue buying? (Yes/No): \")\n", + " \n", + "print(\"Thanks for your purchase.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "3d84c06d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug': 2, 'hat': 3, 'keychain': 5, 'book': 1, 't-shirt': 1}\n" + ] + } + ], + "source": [ + "customer_orders = {'t-shirt'}\n", + "\n", + "for item in customer_orders:\n", + " if item in inventory:\n", + " inventory[item]-=1\n", + " print(inventory)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +135,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,