diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..2b90d20 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,97 @@ "\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": "edba9050", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] #list of products" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "9a6b5c6d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventory: {'t-shirt': 100, 'mug': 100, 'hat': 100, 'book': 1000, 'keychain': 1}\n" + ] + } + ], + "source": [ + "inventory = {} \n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product] = quantity\n", + "print(\"Inventory:\", inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "317214cd", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Customer orders: {'mug'}\n" + ] + } + ], + "source": [ + "customer_orders = set() #empty set to store customer orders\n", + "\n", + "add_more = \"yes\"\n", + "\n", + "while add_more == \"yes\":\n", + " product = input(\"Enter a product to order: \")\n", + " customer_orders.add(product)\n", + "\n", + " add_more = input(\"Do you want to add another product? (yes/no): \").lower()\n", + "\n", + "print(\"Customer orders:\", customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "a33d1124", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 100\n", + "mug: 99\n", + "hat: 100\n", + "book: 1000\n", + "keychain: 1\n" + ] + } + ], + "source": [ + "for product in customer_orders:\n", + " inventory[product] -= 1\n", + "\n", + "for product in inventory:\n", + " print(product + ':', inventory[product])" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +141,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.9" } }, "nbformat": 4,