diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..e0b46e9 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,108 @@ "\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": "299271f0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 7, 'mug': 6, 'hat': 5, 'book': 4, 'keychain': 3}" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 1. \n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", + " inventory[product] = quantity\n", + " \n", + "inventory\n" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "341d09de", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "485efe3e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'hat', 'mug'}" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + " \n", + " #a. \n", + " #b. \n", + " #c. \n", + " #d. \n", + "add_another = 'yes'\n", + "\n", + "while add_another == 'yes':\n", + " product_name = input(\"Enter the name of a product that a customer wants to order: \")\n", + " customer_orders.add(product_name)\n", + "\n", + " add_another = input(\"Do you want to add another product? (yes/no): \")\n", + "\n", + "customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2d07b66f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "products in customer_orders: {'mug', 'book', 'hat'}\n", + "updated inventory: {'t-shirt': 7, 'mug': 5, 'hat': 4, 'book': 3, 'keychain': 3}\n" + ] + } + ], + "source": [ + "#3. \n", + "for product in customer_orders:\n", + " inventory[product] -= 1\n", + "\n", + "print(\"products in customer_orders:\", customer_orders)\n", + "print(\"updated inventory:\", inventory)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +152,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.7" } }, "nbformat": 4,