diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..21ca267 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,109 @@ "\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": "86321976", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "1. Empty set \"customer_orders\"\n", + "2. keep_ordering until user doesn't want to add another product\n", + "3. While loop until user does not want to add another product\n", + "4. Input (\"Enter name of 3 products you want to order: \")\n", + "5. Update inventory by the products that were ordered\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "a38fdf96", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 1. List of products\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "products" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "07be4308", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 44, 'mug': 22, 'hat': 455, 'book': 2, 'keychain': 2}\n" + ] + } + ], + "source": [ + "# 3. Input quantity of each product available in the inventory\n", + "inventory = {}\n", + "for product in products:\n", + " quantity = int(input(f\"Quantity of {product}: \"))\n", + " inventory[product] = (\n", + " quantity # In the inventory dict, at key, store this quantity!!!\n", + " )\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "010dc850", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You have ordered: {'t-shirt', 'hat', 'book'}\n", + "{'t-shirt': 44, 'mug': 22, 'hat': 455, 'book': 2, 'keychain': 2}\n" + ] + } + ], + "source": [ + "customer_orders = set() # Create empty set\n", + "keep_ordering = True # Until it turns false it will loop\n", + "\n", + "while keep_ordering:\n", + " product_choice = input(f\"Enter name of product you want to order: ({products})\")\n", + " customer_orders.add(product_choice)\n", + "\n", + " answer = input(\"Do you want to add another product? (Yes/No)\")\n", + " if answer.lower() == \"yes\":\n", + " keep_ordering = True\n", + " else:\n", + " keep_ordering = False\n", + "\n", + "print(f\"You have ordered: {customer_orders}\")\n", + "\n", + "print(inventory)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +153,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.6" } }, "nbformat": 4,